johnnovak / illwill

A curses inspired simple cross-platform console library for Nim
Do What The F*ck You Want To Public License
398 stars 27 forks source link

How to write inside of a box buffer copied to a terminal buffer #44

Closed idiot-with-a-keyboard closed 9 months ago

idiot-with-a-keyboard commented 9 months ago

Is there a way to make .write overwrite text?

import illwill
import terminal
import math
import std/httpclient
import strutils
let SERV=(((terminalWidth()-1) / 10) * 1).floor().int
let CHAN=(((terminalWidth()-1) / 10) * 2).floor().int
let MSG= (((terminalWidth()-1) / 10) * 7).floor().int
echo SERV+CHAN+MSG,terminalWidth()

illwillInit()
var tb= newTerminalBuffer(terminalWidth(),terminalHeight())
var MenuBuff= newBoxBuffer(terminalWidth(),terminalHeight())
MenuBuff.drawRect(0,0,SERV,terminalHeight()-1,true,true)
MenuBuff.drawRect(SERV,0,SERV+CHAN,terminalHeight()-1,true,true)
MenuBuff.drawRect(SERV+CHAN,0,SERV+CHAN+MSG,terminalHeight()-1,true,true)

tb.write(1,0,"SERVERS")
tb.write(SERV+1,0,"CHANNELS")
tb.write(CHAN+SERV+1,0,"MESSAGE CONTENT")

var client = newHttpClient()
let baretext=client.getContent("https://rentry.org/DISCORDTUITEST/raw").split('\n')
for i in 0..len(baretext)-1:
  tb.write(CHAN+SERV+1,1+i,baretext[i])

illwill.write(tb,MenuBuff)

tb.display()
while getKey()!=Key.Q:discard
illwillDeinit()

This outputs a weird display where all the edges are wonky.

idiot-with-a-keyboard commented 9 months ago

output:

╔════════════╦══════════════════════════╦═════════════════════════════════════════════════════════════════════════════════════════════╗ 
                                                                             ║ 
                                                                            ║ 
                                                                   ║ 
                                                      ║ ryone Shut up you idiot
║            ║                          ║♥ USER #5 to USER #4: 5h tempmute                                                            ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
║            ║                          ║                                                                                             ║ 
╚════════════╩══════════════════════════╩═════════════════════════════════════════════════════════════════════════════════════════════╝