about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--readme.md9
-rw-r--r--res/config411
-rw-r--r--src/config/config.nim8
-rw-r--r--src/io/lineedit.nim141
4 files changed, 54 insertions, 515 deletions
diff --git a/readme.md b/readme.md
index 4263656b..3136ea55 100644
--- a/readme.md
+++ b/readme.md
@@ -31,8 +31,7 @@ most important APIs. Plus some other things.
 Currently implemented features are:
 
 * basic html rendering (very much WIP)
-* custom keybindings
-* compose (basically a mini-IME, I might get rid of it later)
+* fully functioning 2d pager with custom keybindings
 
 Planned features (roughly in order of importance):
 
@@ -45,13 +44,13 @@ Planned features (roughly in order of importance):
 * JavaScript
 * table
 * cookie
-* adblock (use uBO?)
 * SOCKS proxy
 * HTTP proxy
 * image (sixel/kitty)
 * audio
 * video (sixel/kitty)
 * user style sheet w/ editor
+* adblock (use uBO?)
 * frame?
 * extension API?
 * non-unicode charsets?
@@ -61,8 +60,8 @@ Planned features (roughly in order of importance):
 
 ## How do I configure stuff?
 
-Currently only keybindings and compose key combinations can be configured. See
-the res/config file for the default (built-in) configuration.
+Currently only keybindings can be configured. See the res/config file for the
+default (built-in) configuration.
 
 twt will look for a config file in the ~/.config/twt/ directory, so you can
 just copy the one from res/ there and customize that to your liking.
diff --git a/res/config b/res/config
index 8e7eb7f1..872593c1 100644
--- a/res/config
+++ b/res/config
@@ -63,414 +63,3 @@ lemap C-a LINED_BEGIN
 lemap C-e LINED_END
 lemap C-v LINED_ESC
 lemap M-j LINED_COMPOSE_TOGGLE
-
-#compose keybindings
-
-#european
-comp a: ä
-comp o: ö
-comp u: ü
-comp u" ű
-comp o" ő
-
-comp a' á
-comp e' é
-comp i' í
-comp o' ó
-comp u' ú
-
-COMP A: Ä
-COMP O: Ö
-COMP U: Ü
-COMP U" Ű
-COMP O" Ő
-
-COMP A' Á
-COMP E' É
-COMP I' Í
-COMP O' Ó
-COMP U' Ú
-
-comp sS ß
-comp n~ ñ
-
-#hiragana
-comp a あ
-comp i い
-comp u う
-comp e え
-comp o お
-
-comp la ぁ
-comp li ぃ
-comp lu ぅ
-comp le ぇ
-comp lo ぉ
-
-comp ka か
-comp ki き
-comp ku く
-comp ke け
-comp ko こ
-
-comp kka っか
-comp kki っき
-comp kku っく
-comp kke っけ
-comp kko っこ
-
-comp sa さ
-comp shi し
-comp su す
-comp se せ
-comp so そ
-
-comp ssa っさ
-comp sshi っし
-comp ssu っす
-comp sse っせ
-comp sso っそ
-
-comp ta た
-comp chi ち
-comp tsu つ
-comp te て
-comp to と
-
-comp tta った
-comp cchi っち
-comp ttsu っつ
-comp tte って
-comp tto っと
-
-comp na な
-comp ni に
-comp nu ぬ
-comp ne ね
-comp no の
-
-comp ha は
-comp hi ひ
-comp fu ふ
-comp he へ
-comp ho ほ
-
-comp fa ふぁ
-comp fi ふぃ
-comp fe ふぇ
-comp fo ふぉ
-
-comp ma ま
-comp mi み
-comp mu む
-comp me め
-comp mo も
-
-comp ya や
-comp yu ゆ
-comp yo よ
-
-comp ra ら
-comp ri り
-comp ru る
-comp re れ
-comp ro ろ
-
-comp wa わ
-comp wo を
-
-comp ga が
-comp gi ぎ
-comp gu ぐ
-comp ge げ
-comp go ご
-
-comp za ざ
-comp ji じ
-comp zu ず
-comp ze ぜ
-comp zo ぞ
-
-comp da だ
-comp dji ぢ
-comp dzu づ
-comp de で
-comp do ど
-
-comp ba ば
-comp bi び
-comp bu ぶ
-comp be べ
-comp bo ぼ
-
-comp pa ぱ
-comp pi ぴ
-comp pu ぷ
-comp pe ぺ
-comp po ぽ
-
-comp n ん
-comp n' ん
-
-comp kya きゃ
-comp kyu きゅ
-comp kyo きょ
-
-comp sha しゃ
-comp shu しゅ
-comp sho しょ
-
-comp cha ちゃ
-comp chu ちゅ
-comp cho ちょ
-
-comp nya にゃ
-comp nyu にゅ
-comp nyo にょ
-
-comp hya ひゃ
-comp hyu ひゅ
-comp hyo ひょ
-
-comp mya みゃ
-comp myu みゅ
-comp myo みょ
-
-comp rya りゃ
-comp ryu りゅ
-comp ryo りょ
-
-comp gya ぎゃ
-comp gyu ぎゅ
-comp gyo ぎょ
-
-comp ja じゃ
-comp ju じゅ
-comp jo じょ
-
-comp bya びゃ
-comp byu びゅ
-comp byo びょ
-
-comp pya ぴゃ
-comp pyu ぴゅ
-comp pyo ぴょ
-
-comp kwa くゎ
-comp gwa ぐゎ
-
-comp ti ってぃ
-comp tti ってぃ
-
-comp di てぃ
-comp ddi ってぃ
-
-comp kkya っきゃ
-comp kkyu っきゅ
-comp kkyo っきょ
-
-comp ssha っしゃ
-comp sshu っしゅ
-comp ssho っしょ
-
-comp ccha っちゃ
-comp cchu っちゅ
-comp ccho っちょ
-
-comp she しぇ
-comp je じぇ
-
-comp sshe っしぇ
-comp jje っじぇ
-
-#katakana
-comp A ア
-comp I イ
-comp U ウ
-comp E エ
-comp O オ
-
-comp LA ォ
-comp LI ィ
-comp LU ゥ
-comp LE ェ
-comp LO ォ
-
-comp KA カ
-comp KI キ
-comp KU ク
-comp KE ケ
-comp KO コ
-
-comp KKA ッカ
-comp KKI ッキ
-comp KKU ック
-comp KKE ッケ
-comp KKO ッコ
-
-comp SA サ
-comp SHI シ
-comp SU ス
-comp SE セ
-comp SO ソ
-
-comp SSA ッサ
-comp SSHI ッシ
-comp SSU ッス
-comp SSE ッセ
-comp SSO ッソ
-
-comp TA タ
-comp CHI チ
-comp TSU ツ
-comp TE テ
-comp TO ト
-
-comp TTA ッタ
-comp CCHI ッチ
-comp TTSU ッツ
-comp TTE ッテ
-comp TTO ッと
-
-comp NA ナ
-comp NI ニ
-comp NU ヌ
-comp NE ネ
-comp NO ノ
-
-comp HA ハ
-comp HI ヒ
-comp FU フ
-comp HE ヘ
-comp HO ホ
-
-comp FA ファ
-comp FI フィ
-comp FE フェ
-comp FO フォ
-
-comp MA マ
-comp MI ミ
-comp MU ム
-comp ME メ
-comp MO モ
-
-comp YA ヤ
-comp YU ユ
-comp YO ヨ
-
-comp RA ラ
-comp RI リ
-comp RU ル
-comp RE レ
-comp RO ロ
-
-comp WA ワ
-comp WO ヲ
-
-comp GA ガ
-comp GI ギ
-comp GU グ
-comp GE ゲ
-comp GO ゴ
-
-comp ZA ザ
-comp JI ジ
-comp ZU ズ
-comp ZE ゼ
-comp ZO ゾ
-
-comp DA ダ
-comp DJI ヂ
-comp DZU ヅ
-comp DE デ
-comp DO ド
-
-comp BA バ
-comp BI ビ
-comp BU ブ
-comp BE ベ
-comp BO ボ
-
-comp PA パ
-comp PI ピ
-comp PU プ
-comp PE ペ
-comp PO ポ
-
-comp N ン
-comp N' ン
-comp - ー
-
-comp KYA キャ
-comp KYU キュ
-comp KYO キョ
-
-comp SHA シャ
-comp SHU シュ
-comp SHO ショ
-
-comp CHA チャ
-comp CHU チュ
-comp CHO チョ
-
-comp NYA ニャ
-comp NYU ニュ
-comp NYO ニョ
-
-comp HYA ヒャ
-comp HYU ヒュ
-comp HYO ヒョ
-
-comp MYA ミャ
-comp MYU ミュ
-comp MYO ミョ
-
-comp RYA リャ
-comp RYU リュ
-comp RYO リョ
-
-comp GYA ギャ
-comp GYU ギュ
-comp GYO ギョ
-
-comp JA ジャ
-comp JU ジュ
-comp JO ジョ
-
-comp BYA ビャ
-comp BYU ビュ
-comp BYO ビョ
-
-comp PYA ピャ
-comp PYU ピュ
-comp PYO ピョ
-
-comp KWA クヮ
-comp GWA グヮ
-
-comp TI ティ
-comp TTI ッティ
-comp DI ディ
-comp DDI ッディ
-
-comp KKYA ッキャ
-comp KKYU ッキュ
-comp KKYO ッキョ
-
-comp SSHA ッシャ
-comp SSHU ッシュ
-comp SSHO ッショ
-
-comp CCHA ッチャ
-comp CCHU ッチュ
-comp CCHO ッチョ
-
-comp SHE シェ
-comp SSHE ッシェ
-
-comp JE ジェ
-comp JJE ッジェ
-
-comp WI ウィ
-comp WE ウェ
diff --git a/src/config/config.nim b/src/config/config.nim
index dab5347f..d055af53 100644
--- a/src/config/config.nim
+++ b/src/config/config.nim
@@ -37,15 +37,13 @@ type
   StaticConfig = object
     nmap: ActionMap
     lemap: ActionMap
-    cmap: Table[string, string]
 
   Config = object
     nmap*: ActionMap
     lemap*: ActionMap
-    cmap*: RadixNode[string]
 
 func getConfig(s: StaticConfig): Config =
-  return Config(nmap: s.nmap, lemap: s.lemap, cmap: s.cmap.toRadixTree())
+  return Config(nmap: s.nmap, lemap: s.lemap)
 
 func getRealKey(key: string): string =
   var realk: string
@@ -116,8 +114,6 @@ proc parseConfigLine[T](line: string, config: var T) =
       config.nmap[getRealKey(cmd[1])] = parseEnum[TwtAction]("ACTION_" & cmd[2])
     elif cmd[0] == "lemap":
       config.lemap[getRealKey(cmd[1])] = parseEnum[TwtAction]("ACTION_" & cmd[2])
-    elif cmd[0] == "comp":
-      config.cmap[getRealKey(cmd[1])] = cmd[2]
 
 proc staticReadConfig(): StaticConfig =
   let default = staticRead"res/config"
@@ -135,7 +131,6 @@ proc readConfig(filename: string) =
   let status = f.open(filename, fmRead)
   var nmap: ActionMap
   var lemap: ActionMap
-  var compose: Table[string, string]
   if status:
     var line: TaintedString
     while f.readLine(line):
@@ -143,7 +138,6 @@ proc readConfig(filename: string) =
 
     gconfig.nmap = constructActionTable(nmap)
     gconfig.lemap = constructActionTable(lemap)
-    gconfig.cmap = compose.toRadixTree()
 
 proc readConfig*() =
   when defined(debug):
diff --git a/src/io/lineedit.nim b/src/io/lineedit.nim
index e1a552bd..fd2b0b93 100644
--- a/src/io/lineedit.nim
+++ b/src/io/lineedit.nim
@@ -13,10 +13,6 @@ type LineState = object
   s: string
   feedNext: bool
   escNext: bool
-  comp: bool
-  compn: RadixNode[string]
-  compa: int
-  comps: string
   cursor: int
   shift: int
   minlen: int
@@ -25,13 +21,15 @@ type LineState = object
   spaces: seq[string]
 
 proc backward(state: LineState, i: int) =
-  if i == 1:
-    print('\b')
-  else:
-    cursorBackward(i)
+  if i > 0:
+    if i == 1:
+      print('\b')
+    else:
+      cursorBackward(i)
 
 proc forward(state: LineState, i: int) =
-  cursorForward(i)
+  if i > 0:
+    cursorForward(i)
 
 proc begin(state: LineState) =
   print('\r')
@@ -41,57 +39,48 @@ proc begin(state: LineState) =
 proc space(state: LineState, i: int) =
   print(state.spaces[i])
 
-proc kill(state: LineState) =
-  when defined(windows):
-    let w = min(state.news.width(state.cursor), state.displen)
-    state.space(w)
-    state.backward(w)
-  else:
-    print("\e[K")
+template kill(state: LineState, i: int) =
+  state.space(i)
+  state.backward(i)
+  #print("\e[K")
 
-proc fullRedraw(state: var LineState) =
-    state.displen = state.maxlen - 1
-    if state.cursor > state.shift:
-      var shiftw = state.news.width(state.shift, state.cursor)
-      while shiftw > state.maxlen - 1:
-        inc state.shift
-        shiftw -= state.news[state.shift].width()
-    else:
-      state.shift = max(state.cursor - 1, 0)
+template kill(state: LineState) =
+  let w = min(state.news.width(state.cursor), state.displen)
+  state.kill(w)
 
-    var dispw = state.news.width(state.shift, state.shift + state.displen)
-    if state.shift + state.displen > state.news.len:
-      state.displen = state.news.len - state.shift
-    while dispw > state.maxlen - 1:
-      dispw -= state.news[state.shift + state.displen - 1].width()
-      dec state.displen
+proc redraw(state: var LineState) =
+  var dispw = state.news.width(state.shift, state.shift + state.displen)
+  if state.shift + state.displen > state.news.len:
+    state.displen = state.news.len - state.shift
+  while dispw > state.maxlen - 1:
+    dispw -= state.news[state.shift + state.displen - 1].width()
+    dec state.displen
 
-    state.begin()
-    let os = state.news.substr(state.shift, state.shift + state.displen)
-    printesc($os)
-    state.space(max(state.maxlen - os.width(), 0))
+  state.begin()
+  let os = state.news.substr(state.shift, state.shift + state.displen)
+  printesc($os)
+  state.space(max(state.maxlen - state.minlen - os.width(), 0))
 
-    state.begin()
-    state.forward(state.news.width(state.shift, state.cursor))
+  state.begin()
+  state.forward(state.news.width(state.shift, state.cursor))
 
 proc zeroShiftRedraw(state: var LineState) =
   state.shift = 0
   state.displen = state.maxlen - 1
 
-  var dispw = state.news.width(0, state.displen)
-  if state.displen > state.news.len:
-    state.displen = state.news.len
-  while dispw > state.maxlen - 1:
-    dispw -= state.news[state.displen - 1].width()
-    dec state.displen
+  state.redraw()
 
-  state.begin()
-  let os = state.news.substr(0, state.displen)
-  printesc($os)
-  state.space(max(state.maxlen - os.width(), 0))
+proc fullRedraw(state: var LineState) =
+  state.displen = state.maxlen - 1
+  if state.cursor > state.shift:
+    var shiftw = state.news.width(state.shift, state.cursor)
+    while shiftw > state.maxlen - 1:
+      inc state.shift
+      shiftw -= state.news[state.shift].width()
+  else:
+    state.shift = max(state.cursor - 1, 0)
 
-  state.begin()
-  state.forward(state.news.width(0, state.cursor))
+  state.redraw()
 
 proc insertCharseq(state: var LineState, cs: var seq[Rune]) =
   let escNext = state.escNext
@@ -109,40 +98,9 @@ proc insertCharseq(state: var LineState, cs: var seq[Rune]) =
     state.cursor += cs.len
     state.fullRedraw()
 
-proc insertCompose(state: var LineState, c: char) =
-  state.comps &= c
-  let n = state.compn{state.comps}
-  if n != state.compn:
-    state.compn = n
-    state.compa += state.comps.len
-    state.comps = ""
-  if state.compn.hasPrefix(state.comps, state.compn) and n.children.len > 0:
-    state.feedNext = true
-  else:
-    var cs: seq[Rune]
-    if state.compn.leaf:
-      cs = state.compn.value.toRunes()
-    else:
-      cs = state.s.substr(0, state.compa - 1).toRunes()
-    state.comps = state.s.substr(state.compa)
-    if state.comps.len > 0 and gconfig.cmap.hasPrefix(state.comps):
-      state.compa = state.comps.len
-      state.compn = gconfig.cmap{state.comps}
-      state.s = state.comps
-      state.comps = ""
-      state.feedNext = true
-    else:
-      cs &= state.comps.toRunes()
-      state.compa = 0
-      state.compn = gconfig.cmap
-      state.comps = ""
-
-    state.insertCharseq(cs)
-
 proc readLine*(current: var string, minlen: int, maxlen: int): bool =
   var state: LineState
   state.news = current.toRunes()
-  state.compn = gconfig.cmap
   state.cursor = state.news.len
   state.minlen = minlen
   state.maxlen = maxlen
@@ -173,11 +131,18 @@ proc readLine*(current: var string, minlen: int, maxlen: int): bool =
       if state.cursor > 0:
         state.news.delete(state.cursor - 1, state.cursor - 1)
         dec state.cursor
-        state.fullRedraw()
+        if state.cursor == state.news.len and state.shift == 0:
+          state.backward(1)
+          state.kill(1)
+        else:
+          state.fullRedraw()
     of ACTION_LINED_DELETE:
       if state.cursor > 0 and state.cursor < state.news.len:
         state.news.delete(state.cursor, state.cursor)
-        state.fullRedraw()
+        if state.cursor == state.news.len and state.shift == 0:
+          state.kill(1)
+        else:
+          state.fullRedraw()
     of ACTION_LINED_ESC:
       state.escNext = true
     of ACTION_LINED_CLEAR:
@@ -245,10 +210,9 @@ proc readLine*(current: var string, minlen: int, maxlen: int): bool =
         let w = state.news.width(state.cursor - chars, state.cursor)
         state.news.delete(state.cursor - chars, state.cursor - 1)
         state.cursor -= chars
-        if state.cursor > state.news.len and state.shift == 0:
-          state.backward(w)
-          state.space(w)
+        if state.cursor == state.news.len and state.shift == 0:
           state.backward(w)
+          state.kill(w)
         else:
           state.fullRedraw()
     of ACTION_LINED_BEGIN:
@@ -265,15 +229,8 @@ proc readLine*(current: var string, minlen: int, maxlen: int): bool =
         else:
           state.fullRedraw()
         state.cursor = state.news.len
-    of ACTION_LINED_COMPOSE_TOGGLE:
-      state.comp = not state.comp
-      state.compn = gconfig.cmap
-      state.compa = 0
-      state.comps = ""
     of ACTION_FEED_NEXT:
       state.feedNext = true
-    elif state.comp:
-      state.insertCompose(c)
     elif validateUtf8(state.s) == -1:
       var cs = state.s.toRunes()
       state.insertCharseq(cs)