mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
just a 'print file contents' program to make fancy screenshots for social media posts
This commit is contained in:
@@ -188,6 +188,10 @@ class TVDOSFileDescriptor {
|
||||
return this.driver.remove(this)
|
||||
}
|
||||
|
||||
get exists() {
|
||||
return this.driver.exists(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -363,6 +367,9 @@ _TVDOS.DRV.FS.SERIAL.remove = (fd) => {
|
||||
let response = com.getStatusCode(port[0])
|
||||
return (response === 0)
|
||||
}
|
||||
_TVDOS.DRV.FS.SERIAL.exists = (fd) => {
|
||||
return (0 == _TVDOS.DRV.FS.SERIAL._openr(fd))
|
||||
}
|
||||
|
||||
Object.freeze(_TVDOS.DRV.FS.SERIAL)
|
||||
|
||||
@@ -407,6 +414,7 @@ _TVDOS.DRV.FS.DEVRND.touch = () => {}
|
||||
_TVDOS.DRV.FS.DEVRND.mkDir = () => {}
|
||||
_TVDOS.DRV.FS.DEVRND.mkFile = () => {}
|
||||
_TVDOS.DRV.FS.DEVRND.remove = () => {}
|
||||
_TVDOS.DRV.FS.DEVRND.exists = () => true
|
||||
|
||||
Object.freeze(_TVDOS.DRV.FS.DEVRND)
|
||||
|
||||
@@ -434,6 +442,7 @@ _TVDOS.DRV.FS.DEVNUL.touch = () => {}
|
||||
_TVDOS.DRV.FS.DEVNUL.mkDir = () => {}
|
||||
_TVDOS.DRV.FS.DEVNUL.mkFile = () => {}
|
||||
_TVDOS.DRV.FS.DEVNUL.remove = () => {}
|
||||
_TVDOS.DRV.FS.DEVNUL.exists = () => true
|
||||
|
||||
Object.freeze(_TVDOS.DRV.FS.DEVNUL)
|
||||
|
||||
@@ -459,6 +468,7 @@ _TVDOS.DRV.FS.DEVZERO.touch = () => {}
|
||||
_TVDOS.DRV.FS.DEVZERO.mkDir = () => {}
|
||||
_TVDOS.DRV.FS.DEVZERO.mkFile = () => {}
|
||||
_TVDOS.DRV.FS.DEVZERO.remove = () => {}
|
||||
_TVDOS.DRV.FS.DEVZERO.exists = () => true
|
||||
|
||||
Object.freeze(_TVDOS.DRV.FS.DEVZERO)
|
||||
|
||||
@@ -509,6 +519,7 @@ _TVDOS.DRV.FS.DEVCON.touch = () => {}
|
||||
_TVDOS.DRV.FS.DEVCON.mkDir = () => {}
|
||||
_TVDOS.DRV.FS.DEVCON.mkFile = () => {}
|
||||
_TVDOS.DRV.FS.DEVCON.remove = () => {}
|
||||
_TVDOS.DRV.FS.DEVCON.exists = () => true
|
||||
|
||||
Object.freeze(_TVDOS.DRV.FS.DEVCON)
|
||||
|
||||
|
||||
44
assets/disk0/tvdos/bin/printfile.js
Normal file
44
assets/disk0/tvdos/bin/printfile.js
Normal file
@@ -0,0 +1,44 @@
|
||||
const COL_LNUMBACK = 18
|
||||
const COL_LNUMFORE = 253
|
||||
|
||||
let filename = undefined
|
||||
|
||||
if (exec_args !== undefined && exec_args[1] !== undefined) {
|
||||
filename = exec_args[1]
|
||||
}
|
||||
else {
|
||||
println("File to print out?")
|
||||
filename = read()
|
||||
}
|
||||
let driveLetter = _G.shell.getCurrentDrive()
|
||||
let filePath = _G.shell.getPwdString() + filename
|
||||
|
||||
let file = files.open(`${driveLetter}:${filePath}`)
|
||||
|
||||
if (!file.exists) {
|
||||
printerrln("File not found")
|
||||
return 1
|
||||
}
|
||||
|
||||
let textbuffer = file.sread().split("\n")
|
||||
|
||||
function drawLineNumber(lnum) {
|
||||
con.curs_set(0)
|
||||
con.color_pair(COL_LNUMFORE, COL_LNUMBACK)
|
||||
|
||||
if (lnum < 1 || lnum - 1 >= textbuffer.length) print(' ')
|
||||
else if (lnum >= 10000) print(`${String.fromCharCode(64+lnum/10000)}${(""+lnum%10000).padStart(4,'0')}`)
|
||||
else if (lnum >= 1000) print(`${lnum}`)
|
||||
else if (lnum >= 100) print(`${lnum} `)
|
||||
else if (lnum >= 10) print(` ${lnum} `)
|
||||
else print(` ${lnum} `)
|
||||
}
|
||||
|
||||
textbuffer.forEach((line,i) => {
|
||||
drawLineNumber(i + 1)
|
||||
con.reset_graphics()
|
||||
print(' ')
|
||||
println(line)
|
||||
})
|
||||
|
||||
return 0
|
||||
Reference in New Issue
Block a user