Skip to content

Commit 1500cd3

Browse files
committed
fmt: format code
1 parent 4a60f8c commit 1500cd3

29 files changed

+636
-657
lines changed

src/components/build_utils.nim

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@ func getCompilerType*(): CompilerType =
5454
func getArchitecture*(): string {.inline, compileTime.} =
5555
hostCPU
5656

57-
func getArchitectureUAString*: string {.inline, compileTime.} =
57+
func getArchitectureUAString*(): string {.inline, compileTime.} =
5858
case getArchitecture()
59-
of "i386": "x86"
60-
of "alpha", "powerpc", "powerpc64", "sparc", "mips", "mipsel", "mips64": "risc"
61-
of "amd64": "x86_64"
62-
else: getArchitecture()
59+
of "i386":
60+
"x86"
61+
of "alpha", "powerpc", "powerpc64", "sparc", "mips", "mipsel", "mips64":
62+
"risc"
63+
of "amd64":
64+
"x86_64"
65+
else:
66+
getArchitecture()
6367

6468
func getHostOS*(): string {.inline, compileTime.} =
6569
hostOS

src/components/js/process.nim

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,19 @@ import ../../components/web/document as jsdoc
1010
from ../../components/parsers/html/document import HTMLDocument
1111
import ./ipc
1212

13-
type
14-
JSProcess* = object
15-
ipc*: IPCClient
16-
parser*: Parser
17-
runtime*: Runtime
13+
type JSProcess* = object
14+
ipc*: IPCClient
15+
parser*: Parser
16+
runtime*: Runtime
1817

19-
document*: HTMLDocument
18+
document*: HTMLDocument
2019

2120
proc initConsoleIPC*(js: var JSProcess) =
2221
var pJs = addr(js)
2322

2423
attachConsoleDelegate(
2524
proc(level: ConsoleLevel, msg: string) =
26-
pJs[].ipc.send(
27-
JSConsoleMessage(message: msg, level: level)
28-
)
25+
pJs[].ipc.send(JSConsoleMessage(message: msg, level: level))
2926
)
3027

3128
proc jsExecBuffer*(js: var JSProcess, data: string) =
@@ -53,7 +50,7 @@ proc talk(js: var JSProcess, process: FerusProcess) =
5350
let
5451
data = js.ipc.receive()
5552
jdata = tryParseJson(data, JsonNode)
56-
53+
5754
if not *jdata:
5855
warn "Did not get any valid JSON data."
5956
warn data
@@ -70,7 +67,7 @@ proc talk(js: var JSProcess, process: FerusProcess) =
7067
jsExecBuffer(js, data)
7168
of feJSTakeDocument:
7269
let packet = &tryParseJson(data, JSTakeDocument)
73-
70+
7471
js.document = packet.document
7572
else:
7673
discard

src/components/layout/flow/processor.nim

Lines changed: 76 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
## Flow layout processor
22

3-
43
import std/[strutils, tables, logging, options, base64]
54
import vmath, bumpy, pixie, pixie/fonts
65
import ../box
@@ -9,18 +8,17 @@ import ../../shared/sugar
98
import ferus_ipc/[client/prelude, shared]
109
import pretty
1110

12-
type
13-
Layout* = object
14-
cursor*: Vec2
15-
ipc*: IPCClient
16-
width*: int
17-
18-
boxes*: seq[Box]
19-
viewport*: Rect
20-
font*: Font
21-
imageCache*: Table[string, string]
11+
type Layout* = object
12+
cursor*: Vec2
13+
ipc*: IPCClient
14+
width*: int
2215

23-
document*: HTMLDocument
16+
boxes*: seq[Box]
17+
viewport*: Rect
18+
font*: Font
19+
imageCache*: Table[string, string]
20+
21+
document*: HTMLDocument
2422

2523
var
2624
WordLengths: Table[string, int]
@@ -35,7 +33,7 @@ proc getWordLength*(layout: var Layout, word: string): int =
3533

3634
WordLengths[word] = length
3735
WordHeights[word] = bounds.y.int
38-
36+
3937
debug "layout: computed layout width for text \"" & word & "\": " & $length
4038
else:
4139
length = WordLengths[word]
@@ -68,7 +66,7 @@ proc newLayout*(ipc: IPCClient, font: Font): Layout {.inline.} =
6866

6967
layout.cursor.reset()
7068
layout.boxes.reset()
71-
69+
7270
WordLengths[""] = 8
7371
WordHeights[""] = 8
7472

@@ -94,7 +92,13 @@ proc getMaxHeight*(layout: Layout): uint =
9492
list &= restChildren
9593
]#
9694

97-
proc addText*(layout: var Layout, text: string, fontSize: float32, kind: BoxKind, href: Option[string] = none(string)) =
95+
proc addText*(
96+
layout: var Layout,
97+
text: string,
98+
fontSize: float32,
99+
kind: BoxKind,
100+
href: Option[string] = none(string),
101+
) =
98102
var lastHeight: float
99103

100104
for word in text.split(' '):
@@ -112,11 +116,11 @@ proc addText*(layout: var Layout, text: string, fontSize: float32, kind: BoxKind
112116
height: height.uint,
113117
fontSize: fontSize,
114118
href: href,
115-
kind: kind
119+
kind: kind,
116120
)
117121

118122
# echo width
119-
123+
120124
layout.cursor = vec2(layout.cursor.x + width.float, layout.cursor.y)
121125

122126
if lastHeight < height.float:
@@ -134,23 +138,30 @@ proc addBreak*(layout: var Layout) =
134138

135139
proc addHeading*(layout: var Layout, text: string, level: uint = 1) =
136140
layout.addText(
137-
text, case level
138-
of 1: 32f
139-
of 2: 28f
140-
of 3: 24f
141-
of 4: 18f
142-
of 5: 16f
143-
else: raise newException(ValueError, "addHeading given invalid range for level: " & $level); 0f,
144-
kind = BoxKind.Block
141+
text,
142+
case level
143+
of 1:
144+
32f
145+
of 2:
146+
28f
147+
of 3:
148+
24f
149+
of 4:
150+
18f
151+
of 5:
152+
16f
153+
else:
154+
raise
155+
newException(ValueError, "addHeading given invalid range for level: " & $level)
156+
0f,
157+
kind = BoxKind.Block,
145158
)
146159

147160
{.push warning[ImplicitDefaultValue]: off.}
148161
proc addImage*(
149-
layout: var Layout,
150-
content: string,
151-
width, height: Option[uint] = none(uint)
162+
layout: var Layout, content: string, width, height: Option[uint] = none(uint)
152163
) =
153-
let image: Option[Image] =
164+
let image: Option[Image] =
154165
try:
155166
some decodeImage(content)
156167
except PixieError as exc:
@@ -163,16 +174,18 @@ proc addImage*(
163174

164175
var img = &image
165176
let
166-
width = if *width:
167-
&width
168-
else:
169-
img.width.uint
170-
171-
height = if *height:
172-
&height
173-
else:
174-
img.height.uint
175-
177+
width =
178+
if *width:
179+
&width
180+
else:
181+
img.width.uint
182+
183+
height =
184+
if *height:
185+
&height
186+
else:
187+
img.height.uint
188+
176189
img = img.resize(width.int, height.int)
177190
info "Adding image (" & $width & 'x' & $height & ')'
178191

@@ -183,16 +196,18 @@ proc addImage*(
183196
pos: layout.cursor,
184197
width: width,
185198
height: height,
186-
kind: BoxKind.Inline
199+
kind: BoxKind.Inline,
187200
)
188201

189202
layout.cursor = vec2(0f, height.float + 4f)
203+
190204
{.pop.}
191205

192206
proc constructFromElem*(layout: var Layout, elem: HTMLElement) =
193-
template expectText =
207+
template expectText() =
194208
if not *elem.text:
195-
warn "layout: <" & $elem.tag & "> element does not contain any text data, ignoring it."
209+
warn "layout: <" & $elem.tag &
210+
"> element does not contain any text data, ignoring it."
196211
return
197212

198213
case elem.tag
@@ -207,7 +222,9 @@ proc constructFromElem*(layout: var Layout, elem: HTMLElement) =
207222
layout.addText(&elem.text, 14f, kind = BoxKind.Block)
208223
of TAG_A:
209224
expectText
210-
layout.addText(&elem.text, 14f, kind = BoxKind.Inline, href = elem.attribute("href"))
225+
layout.addText(
226+
&elem.text, 14f, kind = BoxKind.Inline, href = elem.attribute("href")
227+
)
211228
of TAG_H1:
212229
expectText
213230
layout.addHeading(&elem.text, 1)
@@ -236,17 +253,18 @@ proc constructFromElem*(layout: var Layout, elem: HTMLElement) =
236253
return
237254

238255
let cached = layout.imageCache.contains(&src)
239-
240-
let content = if not cached:
241-
let transfer = layout.ipc.requestDataTransfer(
242-
ResourceRequired, DataLocation(kind: DataLocationKind.WebRequest, url: &src)
243-
)
244-
if *transfer:
245-
decode((&transfer).data)
256+
257+
let content =
258+
if not cached:
259+
let transfer = layout.ipc.requestDataTransfer(
260+
ResourceRequired, DataLocation(kind: DataLocationKind.WebRequest, url: &src)
261+
)
262+
if *transfer:
263+
decode((&transfer).data)
264+
else:
265+
""
246266
else:
247-
""
248-
else:
249-
layout.imageCache[&src]
267+
layout.imageCache[&src]
250268

251269
layout.imageCache[&src] = content
252270
let widthAttr = elem.attribute("width")
@@ -265,11 +283,10 @@ proc constructFromElem*(layout: var Layout, elem: HTMLElement) =
265283
except ValueError:
266284
warn "<img> tag has invalid height attribute: " & &heightAttr
267285

268-
layout.addImage(
269-
content,
270-
width, height
271-
)
272-
of TAG_SCRIPT: discard # we don't care about this - that's the JS runtime's job
286+
layout.addImage(content, width, height)
287+
of TAG_SCRIPT:
288+
discard
289+
# we don't care about this - that's the JS runtime's job
273290
else:
274291
warn "layout: unhandled tag: " & $elem.tag
275292

@@ -281,7 +298,7 @@ proc constructFromDocument*(layout: var Layout, document: HTMLDocument) =
281298
layout.cursor.reset()
282299

283300
layout.document = document
284-
301+
285302
let head = document.elems[0].children[0]
286303
let body = document.elems[0].children[1]
287304

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
import pkg/[vmath]
22

3-
type
4-
BlockBox* = object
5-
3+
type BlockBox* = object

src/components/layout_v2/node.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type
2020
Before
2121
Inside
2222
After
23-
23+
2424
HitTestResult* = object
2525
node*: ref Node
2626
indexInNode*: int = 0

0 commit comments

Comments
 (0)