diff --git a/src/cli.ts b/src/cli.ts index 4e84fb2..39d66c2 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -20,6 +20,9 @@ const { values: opts } = parseArgs({ init: { type: 'string', }, + 'up-one-line': { + type: 'string', + }, }, }) @@ -65,7 +68,7 @@ const [ttyReader, ttyWriter] = await Promise.all([ const tui = new TUI(ttyReader, ttyWriter) try { - tui.init() + tui.init(opts['up-one-line'] === 'true' ? true : opts['up-one-line'] === 'false' ? false : 'auto') const ctx = await fetchContextWaiting diff --git a/src/tui.ts b/src/tui.ts index 840236b..9547c8c 100644 --- a/src/tui.ts +++ b/src/tui.ts @@ -13,14 +13,18 @@ export class TUI { this.#writer = writer } - init(): void { - const pos = getCursorPosition({ reader: this.#reader, writer: this.#writer }) + init(upOneLine: boolean | 'auto'): void { + if (upOneLine === 'auto') { + const pos = getCursorPosition({ reader: this.#reader, writer: this.#writer }) - // getCursorPosition() ordinary returns 1-based position. - // However, if the process fails, it returns { x: 0, y: 0 }. - const cursorX = Math.max(pos.x, 1) + // getCursorPosition() ordinary returns 1-based position. + // However, if the process fails, it returns { x: 0, y: 0 }. + const cursorX = Math.max(pos.x, 1) - this.#upOneLine = cursorX > 1 + this.#upOneLine = cursorX > 1 + } else { + this.#upOneLine = upOneLine + } if (this.#upOneLine) { this.#writer.writeSync(ansi.text('\n').bytes()) diff --git a/src/widget.eta b/src/widget.eta index fd734b8..30bca6d 100644 --- a/src/widget.eta +++ b/src/widget.eta @@ -1,6 +1,9 @@ _wk_widget() { + local opts + zstyle -a ':wk:*' options opts || opts=() + local res='' - res=$(<%= it.wk_path %> < $TTY 2>&1) + res=$(<%= it.wk_path %> ${=opts} < $TTY 2>&1) local wk_exit=$? zle redisplay