Skip to content

Commit

Permalink
draw: make colors more consistent
Browse files Browse the repository at this point in the history
- replace black background with default in many places
- more consistency accross default mode and 256 colors mode
  • Loading branch information
joachimschmidt557 committed Jul 21, 2024
1 parent 0fcc0b2 commit c3f3cb6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
40 changes: 19 additions & 21 deletions src/draw.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import wcwidth

import core, nimboxext

const
defaultOrBlack = 0

proc sizeToString(size: BiggestInt): string =
let siz = size.int
const
Expand Down Expand Up @@ -122,29 +125,24 @@ proc drawDirEntry(entry: DirEntry, y: int, highlight: bool, selected: bool,
(if isDir: " /" else: sizeToString(entry.info.size)) &
" " &
relativePath
if getFgColors256(entry).isSome:
let
fg = if highlight: fgBlack() else: getFgColors256(entry).get
bg = if highlight: c8(clrWhite) else: c8(clrBlack)
style = if highlight: styBold else: getStyle(entry)
nb.print(0, y, line, fg, bg, style)
else:
nb.print(0, y, line,
(if highlight: fgBlack() else: c8(getFgColor(entry))),
(if highlight: c8(clrWhite) else: c8(clrBlack)),
(if highlight: styBold else: getStyle(entry)))
fgC8 = c8(getFgColor(entry))
fg = if highlight: fgHighlight() else: getFgColors256(entry).get(fgC8)
bg = if highlight: c8(clrWhite) else: defaultOrBlack
style = if highlight: styBold else: getStyle(entry)

nb.print(0, y, line, fg, bg, style)

proc drawHeader(numTabs: int, currentTab: int, nb: var Nimbox) =
let
offsetCd = 6 + (if numTabs > 1: 2*numTabs else: 0)
nb.print(0, 0, "nimmm ", c8(clrYellow), c8(clrBlack), styNone)
nb.print(0, 0, "nimmm ", c8(clrYellow), defaultOrBlack, styNone)
if numTabs > 1:
for i in 1 .. numTabs:
if i == currentTab+1:
nb.print(6+2*(i-1), 0, $(i) & " ", c8(clrYellow), c8(clrBlack), styBold)
nb.print(6+2*(i-1), 0, $(i) & " ", c8(clrYellow), defaultOrBlack, styBold)
else:
nb.print(6+2*(i-1), 0, $(i) & " ")
nb.print(offsetCd, 0, getCurrentDir(), c8(clrYellow), c8(clrBlack), styBold)
nb.print(offsetCd, 0, getCurrentDir(), c8(clrYellow), defaultOrBlack, styBold)

proc drawFooter(index: int, lenEntries: int, lenSelected: int, hidden: bool,
search: bool, errMsg: string, nb: var Nimbox) =
Expand All @@ -157,15 +155,15 @@ proc drawFooter(index: int, lenEntries: int, lenSelected: int, hidden: bool,
offsetSelected = offsetS + (if search: 2 else: 0)
offsetErrMsg = offsetSelected + (if lenSelected >
0: selectedStr.len else: 0)
nb.print(0, y, entriesStr, c8(clrYellow), c8(clrBlack))
nb.print(0, y, entriesStr, c8(clrYellow), defaultOrBlack)
if hidden:
nb.print(offsetH, y, " H", c8(clrYellow), c8(clrBlack), styBold)
nb.print(offsetH, y, " H", c8(clrYellow), defaultOrBlack, styBold)
if search:
nb.print(offsetS, y, " S", c8(clrYellow), c8(clrBlack), styBold)
nb.print(offsetS, y, " S", c8(clrYellow), defaultOrBlack, styBold)
if lenSelected > 0:
nb.print(offsetSelected, y, selectedStr)
if errMsg.len > 0:
nb.print(offsetErrMsg, y, " " & errMsg, c8(clrRed), c8(clrBlack))
nb.print(offsetErrMsg, y, " " & errMsg, c8(clrRed), defaultOrBlack)
nb.cursor = (TB_HIDE_CURSOR, TB_HIDE_CURSOR)

proc drawInputFooter(prompt: string, query: string, cursorPos: int,
Expand All @@ -174,8 +172,8 @@ proc drawInputFooter(prompt: string, query: string, cursorPos: int,
y = nb.height() - 1
offset = prompt.wcswidth + 1
cursorPos = offset + query[0..cursorPos - 1].wcswidth
nb.print(0, y, prompt, c8(clrYellow), c8(clrBlack))
nb.print(offset, y, query, c8(clrYellow), c8(clrBlack))
nb.print(0, y, prompt, c8(clrYellow), defaultOrBlack)
nb.print(offset, y, query, defaultOrBlack, defaultOrBlack)
nb.cursor = (cursorPos, y)

proc errMsg(err: ErrorKind): string =
Expand Down Expand Up @@ -211,7 +209,7 @@ proc redraw*(s: State, nb: var Nimbox) =
"Empty directory"
else:
"No matching results"
nb.print(0, 2, message, c8(clrYellow), c8(clrBlack))
nb.print(0, 2, message, c8(clrYellow), defaultOrBlack)
for i in topIndex .. bottomIndex:
let entry = s.entries[s.visibleEntries[i]]
drawDirEntry(entry,
Expand Down
2 changes: 1 addition & 1 deletion src/external.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import std/[os, osproc, sets, sequtils]

proc spawnShell*() =
const
fallback = "/bin/sh"
fallback = "sh"
stdout.writeLine("""
/\^/\^/\^/\
Expand Down
6 changes: 3 additions & 3 deletions src/nimboxext.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ template c8*(color: Color): int =
## with regards to the current color mode
c8(ord(color))

template fgBlack*(): int =
## Provides a viable foreground-black color
template fgHighlight*(): int =
## Provides a viable foreground color for highlighted items
if colors256Mode():
8
16
else:
ord(clrBlack)

0 comments on commit c3f3cb6

Please sign in to comment.