mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
docs/readmes: format almost all remaining code blocks (#8590)
This commit is contained in:
@ -4,40 +4,40 @@ A V module for designing terminal UI apps
|
||||
|
||||
#### Quickstart
|
||||
|
||||
```v nofmt
|
||||
```v
|
||||
import term.ui as tui
|
||||
|
||||
struct App {
|
||||
mut:
|
||||
tui &tui.Context = 0
|
||||
tui &tui.Context = 0
|
||||
}
|
||||
|
||||
fn event(e &tui.Event, x voidptr) {
|
||||
mut app := &App(x)
|
||||
println(e)
|
||||
mut app := &App(x)
|
||||
println(e)
|
||||
}
|
||||
|
||||
fn frame(x voidptr) {
|
||||
mut app := &App(x)
|
||||
mut app := &App(x)
|
||||
|
||||
app.tui.clear()
|
||||
app.tui.set_bg_color(r: 63, g: 81, b: 181)
|
||||
app.tui.draw_rect(20, 6, 41, 10)
|
||||
app.tui.draw_text(24, 8, 'Hello from V!')
|
||||
app.tui.set_cursor_position(0, 0)
|
||||
app.tui.clear()
|
||||
app.tui.set_bg_color(r: 63, g: 81, b: 181)
|
||||
app.tui.draw_rect(20, 6, 41, 10)
|
||||
app.tui.draw_text(24, 8, 'Hello from V!')
|
||||
app.tui.set_cursor_position(0, 0)
|
||||
|
||||
app.tui.reset()
|
||||
app.tui.flush()
|
||||
app.tui.reset()
|
||||
app.tui.flush()
|
||||
}
|
||||
|
||||
mut app := &App{}
|
||||
app.tui = tui.init(
|
||||
user_data: app,
|
||||
event_fn: event,
|
||||
frame_fn: frame
|
||||
hide_cursor: true
|
||||
user_data: app
|
||||
event_fn: event
|
||||
frame_fn: frame
|
||||
hide_cursor: true
|
||||
)
|
||||
app.tui.run()
|
||||
app.tui.run() ?
|
||||
```
|
||||
|
||||
See the `/examples/term.ui/` folder for more usage examples.
|
||||
|
@ -4,51 +4,51 @@
|
||||
`x.json2` is an experimental JSON parser written from scratch on V.
|
||||
|
||||
## Usage
|
||||
```v oksyntax nofmt
|
||||
```v oksyntax
|
||||
import x.json2
|
||||
import net.http
|
||||
|
||||
fn main() {
|
||||
// Decoding
|
||||
resp := http.get('https://example.com')?
|
||||
// Decoding
|
||||
resp := http.get('https://example.com') ?
|
||||
|
||||
// raw decode
|
||||
raw_person := json2.raw_decode(resp.text)?
|
||||
// raw decode
|
||||
raw_person := json2.raw_decode(resp.text) ?
|
||||
|
||||
// Casting `Any` type / Navigating
|
||||
person := raw_person.as_map()
|
||||
name := person['name'].str() // Bob
|
||||
age := person['age'].int() // 19
|
||||
pi := person['pi'].f64() // 3.14....
|
||||
// Casting `Any` type / Navigating
|
||||
person := raw_person.as_map()
|
||||
name := person['name'].str() // Bob
|
||||
age := person['age'].int() // 19
|
||||
pi := person['pi'].f64() // 3.14....
|
||||
|
||||
// Constructing an `Any` type
|
||||
mut me := map[string]json2.Any
|
||||
me['name'] = 'Bob'
|
||||
me['age'] = 18
|
||||
// Constructing an `Any` type
|
||||
mut me := map[string]json2.Any{}
|
||||
me['name'] = 'Bob'
|
||||
me['age'] = 18
|
||||
|
||||
mut arr := []json2.Any
|
||||
arr << 'rock'
|
||||
arr << 'papers'
|
||||
arr << json2.null
|
||||
arr << 12
|
||||
mut arr := []json2.Any{}
|
||||
arr << 'rock'
|
||||
arr << 'papers'
|
||||
arr << json2.null
|
||||
arr << 12
|
||||
|
||||
me['interests'] = arr
|
||||
me['interests'] = arr
|
||||
|
||||
mut pets := map[string]json2.Any
|
||||
pets['Sam'] = 'Maltese Shitzu'
|
||||
me['pets'] = pets
|
||||
mut pets := map[string]json2.Any{}
|
||||
pets['Sam'] = 'Maltese Shitzu'
|
||||
me['pets'] = pets
|
||||
|
||||
// Stringify to JSON
|
||||
println(me.str())
|
||||
//{
|
||||
// "name":"Bob",
|
||||
// "age":18,
|
||||
// "interests":["rock","papers","scissors",null,12],
|
||||
// "pets":{"Sam":"Maltese"}
|
||||
//}
|
||||
// Stringify to JSON
|
||||
println(me.str())
|
||||
//{
|
||||
// "name":"Bob",
|
||||
// "age":18,
|
||||
// "interests":["rock","papers","scissors",null,12],
|
||||
// "pets":{"Sam":"Maltese"}
|
||||
//}
|
||||
|
||||
// Encode a struct/type to JSON
|
||||
encoded_json := json2.encode<Person>(person2)
|
||||
// Encode a struct/type to JSON
|
||||
encoded_json := json2.encode<Person>(person2)
|
||||
}
|
||||
```
|
||||
## Using `decode<T>` and `encode<T>`
|
||||
|
Reference in New Issue
Block a user