aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2021-11-20 19:22:36 +0100
committerbptato <nincsnevem662@gmail.com>2021-11-20 19:22:36 +0100
commitfae6b15f8fe7d59caa61b2295e6b71d89b70a795 (patch)
tree51ed366543ee9454c1d2ee94c8849c49353f13ba /src
parentc7347c46b6bbce1194849ae5c8612b17b2b396ed (diff)
downloadchawan-fae6b15f8fe7d59caa61b2295e6b71d89b70a795.tar.gz
Bugfixes & documentation
Diffstat (limited to 'src')
-rw-r--r--src/config/config.nim13
-rw-r--r--src/io/buffer.nim36
-rw-r--r--src/io/term.nim3
3 files changed, 25 insertions, 27 deletions
diff --git a/src/config/config.nim b/src/config/config.nim
index 89f80fae..91b17dda 100644
--- a/src/config/config.nim
+++ b/src/config/config.nim
@@ -14,7 +14,6 @@ type
ACTION_CURSOR_UP, ACTION_CURSOR_DOWN, ACTION_CURSOR_LEFT, ACTION_CURSOR_RIGHT,
ACTION_CURSOR_LINEEND, ACTION_CURSOR_LINEBEGIN,
ACTION_CURSOR_NEXT_WORD, ACTION_CURSOR_PREV_WORD,
- ACTION_CURSOR_NEXT_NODE, ACTION_CURSOR_PREV_NODE,
ACTION_CURSOR_NEXT_LINK, ACTION_CURSOR_PREV_LINK,
ACTION_PAGE_DOWN, ACTION_PAGE_UP, ACTION_PAGE_LEFT, ACTION_PAGE_RIGHT,
ACTION_HALF_PAGE_DOWN, ACTION_HALF_PAGE_UP,
@@ -31,7 +30,7 @@ type
ACTION_LINED_BACK, ACTION_LINED_FORWARD,
ACTION_LINED_PREV_WORD, ACTION_LINED_NEXT_WORD,
ACTION_LINED_BEGIN, ACTION_LINED_END,
- ACTION_LINED_COMPOSE_TOGGLE, ACTION_LINED_ESC
+ ACTION_LINED_ESC
ActionMap = Table[string, TwtAction]
StaticConfig = object
@@ -148,9 +147,15 @@ proc parseConfigLine[T](line: string, config: var T) =
if cmd.len == 3:
if cmd[0] == "nmap":
- config.nmap[getRealKey(cmd[1])] = parseEnum[TwtAction]("ACTION_" & cmd[2])
+ if cmd[2] == "NULL":
+ config.nmap[getRealKey(cmd[1])] = NO_ACTION
+ else:
+ config.nmap[getRealKey(cmd[1])] = parseEnum[TwtAction]("ACTION_" & cmd[2])
elif cmd[0] == "lemap":
- config.lemap[getRealKey(cmd[1])] = parseEnum[TwtAction]("ACTION_" & cmd[2])
+ if cmd[2] == "NULL":
+ config.lemap[getRealKey(cmd[1])] = NO_ACTION
+ else:
+ config.lemap[getRealKey(cmd[1])] = parseEnum[TwtAction]("ACTION_LINED_" & cmd[2])
elif cmd.len == 2:
if cmd[0] == "stylesheet":
config.stylesheet = cmd[1]
diff --git a/src/io/buffer.nim b/src/io/buffer.nim
index 35f5f0f3..e0751964 100644
--- a/src/io/buffer.nim
+++ b/src/io/buffer.nim
@@ -56,25 +56,26 @@ func newBuffer*(attrs: TermAttributes): Buffer =
result.prevdisplay = newFixedGrid(result.width, result.height)
result.statusmsg = newFixedGrid(result.width)
-func generateFullOutput*(buffer: Buffer): seq[string] =
+func generateFullOutput*(buffer: Buffer): string =
var x = 0
- var y = 0
- var s = ""
+ var w = 0
var formatting = newFormatting()
for cell in buffer.display:
if x >= buffer.width:
- inc y
- result.add(s)
+ if w < buffer.width:
+ result &= EL()
+ result &= '\n'
x = 0
- s = ""
+ w = 0
- s &= formatting.processFormatting(cell.formatting)
+ result &= formatting.processFormatting(cell.formatting)
- s &= $cell.runes
+ result &= $cell.runes
+ w += cell.runes.width()
inc x
- result.add(s)
+ result &= EL()
# generate a sequence of instructions to replace the previous frame with the
# current one. ideally should be used when small changes are made (e.g. hover
@@ -725,7 +726,7 @@ proc reshapeBuffer*(buffer: Buffer) =
proc cursorBufferPos(buffer: Buffer) =
let x = max(buffer.cursorx - buffer.fromx, 0)
let y = buffer.cursory - buffer.fromy
- termGoto(x, y)
+ print(HVP(y + 1, x + 1))
proc clearStatusMessage(buffer: Buffer) =
buffer.statusmsg = newFixedGrid(buffer.width)
@@ -753,15 +754,11 @@ proc displayBufferSwapOutput(buffer: Buffer) =
print(buffer.generateSwapOutput())
proc displayBuffer(buffer: Buffer) =
- termGoto(0, 0)
- let full = buffer.generateFullOutput()
- for line in full:
- print(line)
- print(EL())
- print('\n')
+ print(HVP(1, 1))
+ print(buffer.generateFullOutput())
proc displayStatusMessage(buffer: Buffer) =
- termGoto(0, buffer.height)
+ print(HVP(buffer.height + 1, 1))
print(SGR())
print(buffer.generateStatusMessage())
print(EL())
@@ -786,7 +783,7 @@ proc inputLoop(attrs: TermAttributes, buffer: Buffer): bool =
case action
of ACTION_QUIT:
eraseScreen()
- setCursorPos(0, 0)
+ print(HVP(0, 0))
return false
of ACTION_CURSOR_LEFT: buffer.cursorLeft()
of ACTION_CURSOR_DOWN: buffer.cursorDown()
@@ -819,7 +816,7 @@ proc inputLoop(attrs: TermAttributes, buffer: Buffer): bool =
of ACTION_CHANGE_LOCATION:
var url = $buffer.location
- termGoto(0, buffer.height)
+ print(HVP(buffer.height + 1, 1))
print(EL())
let status = readLine("URL: ", url, buffer.width)
if status:
@@ -850,7 +847,6 @@ proc inputLoop(attrs: TermAttributes, buffer: Buffer): bool =
buffer.displayBuffer()
buffer.redraw = false
- #TODO
buffer.updateHover()
if buffer.reshape:
buffer.reshapeBuffer()
diff --git a/src/io/term.nim b/src/io/term.nim
index d60d5746..dc54a34c 100644
--- a/src/io/term.nim
+++ b/src/io/term.nim
@@ -26,6 +26,3 @@ proc getTermAttributes*(): TermAttributes =
result.height = 24
result.ppc = 9
result.ppl = 18
-
-proc termGoto*(x: int, y: int) =
- setCursorPos(stdout, x, y)