Skip to content

Commit

Permalink
fix(lib): optimize code and avoid type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pysan3 committed Oct 24, 2023
1 parent 55091d5 commit d487bad
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions tuicrown/tuicontrol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import std/sequtils
import std/strutils
import std/strformat
import std/os
import std/sugar
import std/terminal

import utils
Expand Down Expand Up @@ -34,7 +33,7 @@ proc newTuiControl*(t: ControlType, title: string): TuiControl =
TuiControl(typ: t, title: title)

proc newTuiControl*(t: ControlType, args: seq[string]): TuiControl =
newTuiControl(t, args.map((x: string) => $x).join(" "))
newTuiControl(t, args.mapIt($it).join(" "))

proc newTuiControl*(t: ControlType, args: seq[int]): TuiControl =
if t <= HIDE_CURSOR:
Expand All @@ -48,7 +47,7 @@ proc newTuiControl*(t: ControlType, args: seq[int]): TuiControl =
y = argsWithDefault(args, 1, 1)
return TuiControl(typ: t, args: @[x, y])
else:
var targs = args.map((x) => $x)
var targs = args.mapIt($it)
if targs.len == 0:
targs.add(getAppFilename().substr(getAppDir().len + 1))
when declared(commandLineParams):
Expand Down
2 changes: 1 addition & 1 deletion tuicrown/tuisegment.nim
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ proc fromString*(text: string): seq[TuiSegment] {.discardable.} =
accumfrom: int = 0
defer: result.keepItIf(it.len > 0)
result.add(newTuiSegment())
for i, s in enumerate(text):
for (i, s) in enumerate(text):
if s == '[':
blockstart = if blockstart < 0: i + 1 else: -1
if blockstart > 1:
Expand Down
6 changes: 3 additions & 3 deletions tuicrown/tuistyles.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import fungus

import utils

adtEnum(TuiFGType):
adtEnum TuiFGType:
TuiFGNone
TuiForegroundColor: ForegroundColor
TuiFGColor: Color
adtEnum(TuiBGType):
adtEnum TuiBGType:
TuiBGNone
TuiBackgroundColor: BackgroundColor
TuiBGColor: Color
Expand Down Expand Up @@ -101,7 +101,7 @@ func `bgColor+`*(self: TuiStyles, o: seq[TuiBGType]): auto =

proc print*(f: File, self: TuiStyles) =
var isBright = self.styles.anyIt(it == styleBright)
f.write(self.styles.map(ansiStyleCode).join(""))
f.write(self.styles.mapIt(it.int).map(ansiStyleCode).join(""))
match self.bgColor:
of TuiBackgroundColor as bg_0:
f.setBackgroundColor(bg_0, isBright)
Expand Down

0 comments on commit d487bad

Please sign in to comment.