docs/readmes: format almost all remaining code blocks (#8590)

pull/8593/head^2
Lukas Neubert 2021-02-05 18:50:28 +01:00 committed by GitHub
parent 576492af4e
commit 58b3a30b47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 76 deletions

View File

@ -418,7 +418,7 @@ Literals like `123` or `4.56` are treated in a special way. They do
not lead to type promotions, however they default to `int` and `f64` not lead to type promotions, however they default to `int` and `f64`
respectively, when their type has to be decided: respectively, when their type has to be decided:
```v ignore ```v nofmt
u := u16(12) u := u16(12)
v := 13 + u // v is of type `u16` - no promotion v := 13 + u // v is of type `u16` - no promotion
x := f32(45.6) x := f32(45.6)
@ -718,7 +718,7 @@ numbers.sort() // 1, 2, 3
numbers.sort(a > b) // 3, 2, 1 numbers.sort(a > b) // 3, 2, 1
``` ```
```v nofmt ```v
struct User { struct User {
age int age int
name string name string
@ -1487,7 +1487,7 @@ assert button.height == 20
As you can see, both the struct name and braces can be omitted, instead of: As you can see, both the struct name and braces can be omitted, instead of:
```v ignore ```v oksyntax nofmt
new_button(ButtonConfig{text:'Click me', width:100}) new_button(ButtonConfig{text:'Click me', width:100})
``` ```
@ -1499,7 +1499,7 @@ Struct fields are private and immutable by default (making structs immutable as
Their access modifiers can be changed with Their access modifiers can be changed with
`pub` and `mut`. In total, there are 5 possible options: `pub` and `mut`. In total, there are 5 possible options:
```v nofmt ```v
struct Foo { struct Foo {
a int // private immutable (default) a int // private immutable (default)
mut: mut:
@ -1510,9 +1510,9 @@ pub:
pub mut: pub mut:
e int // public, but mutable only in parent module e int // public, but mutable only in parent module
__global: __global:
// (not recommended to use, that's why the 'global' keyword starts with __)
f int // public and mutable both inside and outside parent module f int // public and mutable both inside and outside parent module
} // (not recommended to use, that's why the 'global' keyword }
// starts with __)
``` ```
For example, here's the `string` type defined in the `builtin` module: For example, here's the `string` type defined in the `builtin` module:
@ -1587,7 +1587,7 @@ intended for low-level applications like kernels and drivers.
It is possible to modify function arguments by using the keyword `mut`: It is possible to modify function arguments by using the keyword `mut`:
```v nofmt ```v
struct User { struct User {
name string name string
mut: mut:
@ -1803,7 +1803,7 @@ module, and inside it. That restriction is relaxed only for the `main` module
constants too, i.e. just `println(numbers)`, not `println(main.numbers)` . constants too, i.e. just `println(numbers)`, not `println(main.numbers)` .
vfmt takes care of this rule, so you can type `println(pi)` inside the `math` module, vfmt takes care of this rule, so you can type `println(pi)` inside the `math` module,
and vffmt will automatically update it to `println(math.pi)`. and vfmt will automatically update it to `println(math.pi)`.
<!-- <!--
Many people prefer all caps consts: `TOP_CITIES`. This wouldn't work Many people prefer all caps consts: `TOP_CITIES`. This wouldn't work
@ -1812,8 +1812,8 @@ They can represent complex structures, and this is used quite often since there
are no globals: are no globals:
--> -->
```v ignore ```v oksyntax
println('Top cities: $top_cities.filter(.usa)') println('Top cities: ${top_cities.filter(.usa)}')
``` ```
## Builtin functions ## Builtin functions
@ -1835,8 +1835,12 @@ fn print_backtrace() // print backtraces on stderr
`println` is a simple yet powerful builtin function, that can print anything: `println` is a simple yet powerful builtin function, that can print anything:
strings, numbers, arrays, maps, structs. strings, numbers, arrays, maps, structs.
```v nofmt ```v
struct User{ name string age int } struct User {
name string
age int
}
println(1) // "1" println(1) // "1"
println('hi') // "hi" println('hi') // "hi"
println([1, 2, 3]) // "[1, 2, 3]" println([1, 2, 3]) // "[1, 2, 3]"

View File

@ -4,7 +4,7 @@ A V module for designing terminal UI apps
#### Quickstart #### Quickstart
```v nofmt ```v
import term.ui as tui import term.ui as tui
struct App { struct App {
@ -32,12 +32,12 @@ fn frame(x voidptr) {
mut app := &App{} mut app := &App{}
app.tui = tui.init( app.tui = tui.init(
user_data: app, user_data: app
event_fn: event, event_fn: event
frame_fn: frame frame_fn: frame
hide_cursor: true hide_cursor: true
) )
app.tui.run() app.tui.run() ?
``` ```
See the `/examples/term.ui/` folder for more usage examples. See the `/examples/term.ui/` folder for more usage examples.

View File

@ -4,7 +4,7 @@
`x.json2` is an experimental JSON parser written from scratch on V. `x.json2` is an experimental JSON parser written from scratch on V.
## Usage ## Usage
```v oksyntax nofmt ```v oksyntax
import x.json2 import x.json2
import net.http import net.http
@ -22,11 +22,11 @@ fn main() {
pi := person['pi'].f64() // 3.14.... pi := person['pi'].f64() // 3.14....
// Constructing an `Any` type // Constructing an `Any` type
mut me := map[string]json2.Any mut me := map[string]json2.Any{}
me['name'] = 'Bob' me['name'] = 'Bob'
me['age'] = 18 me['age'] = 18
mut arr := []json2.Any mut arr := []json2.Any{}
arr << 'rock' arr << 'rock'
arr << 'papers' arr << 'papers'
arr << json2.null arr << json2.null
@ -34,7 +34,7 @@ fn main() {
me['interests'] = arr me['interests'] = arr
mut pets := map[string]json2.Any mut pets := map[string]json2.Any{}
pets['Sam'] = 'Maltese Shitzu' pets['Sam'] = 'Maltese Shitzu'
me['pets'] = pets me['pets'] = pets