« get me outta code hell

use ESM module syntax & minor cleanups - tui-lib - Pure Node.js library for making visual command-line programs (ala vim, ncdu)
about summary refs log tree commit diff
path: root/ui/Pane.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-05-12 17:42:09 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-05-13 12:48:36 -0300
commit6ea74c268a12325296a1d2e7fc31b02030ddb8bc (patch)
tree5da94d93acb64e7ab650d240d6cb23c659ad02ca /ui/Pane.js
parente783bcf8522fa68e6b221afd18469c3c265b1bb7 (diff)
use ESM module syntax & minor cleanups
The biggest change here is moving various element classes under
more scope-specific directories, which helps to avoid circular
dependencies and is just cleaner to navigate and expand in the
future.

Otherwise this is a largely uncritical port to ESM module syntax!
There are probably a number of changes and other cleanups that
remain much needed.

Whenever I make changes to tui-lib it's hard to believe it's
already been <INSERT COUNTING NUMBER HERE> years since the
previous time. First commits are from January 2017, and the
code originates a month earlier in KAaRMNoD!
Diffstat (limited to 'ui/Pane.js')
-rw-r--r--ui/Pane.js101
1 files changed, 0 insertions, 101 deletions
diff --git a/ui/Pane.js b/ui/Pane.js
deleted file mode 100644
index b33a1b7..0000000
--- a/ui/Pane.js
+++ /dev/null
@@ -1,101 +0,0 @@
-const ansi = require('../util/ansi')
-const unic = require('../util/unichars')
-
-const DisplayElement = require('./DisplayElement')
-
-const Label = require('./Label')
-
-module.exports = class Pane extends DisplayElement {
-  // A simple rectangular framed pane.
-
-  constructor() {
-    super()
-
-    this.frameColor = null
-
-    this.hPadding = 1
-    this.vPadding = 1
-  }
-
-  drawTo(writable) {
-    this.drawFrame(writable)
-    super.drawTo(writable)
-  }
-
-  drawFrame(writable, debug=false) {
-    writable.write(ansi.setForeground(this.frameColor))
-
-    const left = this.absLeft
-    const right = this.absRight
-    const top = this.absTop
-    const bottom = this.absBottom
-
-    // Background
-    // (TODO) Transparent background (that dimmed everything behind it) would
-    // be cool at some point!
-    for (let y = top + 1; y <= bottom - 1; y++) {
-      writable.write(ansi.moveCursor(y, left))
-      writable.write(' '.repeat(this.w))
-    }
-
-    // Left/right edges
-    for (let x = left + 1; x <= right - 1; x++) {
-      writable.write(ansi.moveCursor(top, x))
-      writable.write(unic.BOX_H)
-      writable.write(ansi.moveCursor(bottom, x))
-      writable.write(unic.BOX_H)
-    }
-
-    // Top/bottom edges
-    for (let y = top + 1; y <= bottom - 1; y++) {
-      writable.write(ansi.moveCursor(y, left))
-      writable.write(unic.BOX_V)
-      writable.write(ansi.moveCursor(y, right))
-      writable.write(unic.BOX_V)
-    }
-
-    // Corners
-    writable.write(ansi.moveCursor(top, left))
-    writable.write(unic.BOX_CORNER_TL)
-    writable.write(ansi.moveCursor(top, right))
-    writable.write(unic.BOX_CORNER_TR)
-    writable.write(ansi.moveCursor(bottom, left))
-    writable.write(unic.BOX_CORNER_BL)
-    writable.write(ansi.moveCursor(bottom, right))
-    writable.write(unic.BOX_CORNER_BR)
-
-    // Debug info
-    if (debug) {
-      writable.write(ansi.moveCursor(6, 8))
-      writable.write(
-        `x: ${this.x}; y: ${this.y}; w: ${this.w}; h: ${this.h}`)
-      writable.write(ansi.moveCursor(7, 8))
-      writable.write(`AbsX: ${this.absX}; AbsY: ${this.absY}`)
-      writable.write(ansi.moveCursor(8, 8))
-      writable.write(`Left: ${this.left}; Right: ${this.right}`)
-      writable.write(ansi.moveCursor(9, 8))
-      writable.write(`Top: ${this.top}; Bottom: ${this.bottom}`)
-    }
-
-    writable.write(ansi.setForeground(ansi.C_RESET))
-  }
-
-  static alert(parent, text) {
-    // Show an alert pane in the bottom left of the given parent element for
-    // a couple seconds.
-
-    const pane = new Pane()
-    pane.frameColor = ansi.C_WHITE
-    pane.w = ansi.measureColumns(text) + 2
-    pane.h = 3
-    parent.addChild(pane)
-
-    const label = new Label(text)
-    label.textAttributes = [ansi.C_WHITE]
-    pane.addChild(label)
-
-    setTimeout(() => {
-      parent.removeChild(pane)
-    }, 2000)
-  }
-}