Add console module
This commit is contained in:
parent
e4e0dcd1b0
commit
1b0945fed8
4 changed files with 148 additions and 19 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import sets, strutils
|
import sets, strutils
|
||||||
import libnx/graphics
|
import libnx/graphics
|
||||||
import libnx/wrapper/con
|
import libnx/console
|
||||||
import libnx/ext/integer128
|
import libnx/ext/integer128
|
||||||
import libnx/account
|
import libnx/account
|
||||||
import libnx/input
|
import libnx/input
|
||||||
|
|
@ -8,40 +8,42 @@ import libnx/app
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
graphics.initDefault()
|
graphics.initDefault()
|
||||||
discard consoleInit(nil)
|
console.init()
|
||||||
|
|
||||||
echo "\x1b[5;2H" & "Account info:"
|
printAt (5, 2), "Account info:"
|
||||||
|
|
||||||
withAccountService:
|
withAccountService:
|
||||||
try:
|
try:
|
||||||
let user = getActiveUser()
|
let
|
||||||
let userID = user.id
|
user = getActiveUser()
|
||||||
echo "\x1b[6;2HUserID: 0x" & userID.toHex()
|
userID = user.id
|
||||||
echo "\x1b[7;2HUsername: " & user.username
|
|
||||||
echo "\x1b[8;2HMiiID: " & $user.miiID
|
print "UserID: 0x" & userID.toHex()
|
||||||
echo "\x1b[9;2HIconID: " & $user.iconID
|
print "Username: " & user.username
|
||||||
|
print "MiiID: " & $user.miiID
|
||||||
|
print "IconID: " & $user.iconID
|
||||||
except AccountUserNotSelectedError:
|
except AccountUserNotSelectedError:
|
||||||
echo "\x1b[6;2HNo user currently selected!"
|
print "No user currently selected!"
|
||||||
except AccountError:
|
except AccountError:
|
||||||
let msg = getCurrentExceptionMsg()
|
let msg = getCurrentExceptionMsg()
|
||||||
echo "\x1b[6;2H" & msg
|
print msg
|
||||||
|
|
||||||
try:
|
try:
|
||||||
let users = listAllUsers()
|
let users = listAllUsers()
|
||||||
echo ""
|
print ""
|
||||||
echo " There are $# users:" % $users.len()
|
print "There are $# users:" % $users.len()
|
||||||
for user in users:
|
for user in users:
|
||||||
echo " User: " & user.username
|
print "User: " & user.username
|
||||||
except AccountUserListError:
|
except AccountUserListError:
|
||||||
let msg = getCurrentExceptionMsg()
|
let msg = getCurrentExceptionMsg()
|
||||||
echo msg
|
print msg
|
||||||
|
|
||||||
|
|
||||||
mainLoop:
|
mainLoop:
|
||||||
let keysDown = keysDown(Controller.P1_AUTO)
|
let keysDown = keysDown(Controller.P1_AUTO)
|
||||||
|
|
||||||
if keysDown.len() > 0:
|
if keysDown.len() > 0:
|
||||||
echo keysDown
|
print keysDown
|
||||||
|
|
||||||
if ControllerKey.Plus in keysDown:
|
if ControllerKey.Plus in keysDown:
|
||||||
break
|
break
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import sets
|
import sets
|
||||||
import libnx/graphics
|
import libnx/graphics
|
||||||
import libnx/wrapper/con
|
import libnx/console
|
||||||
import libnx/wrapper/hid
|
import libnx/wrapper/hid
|
||||||
import libnx/app
|
import libnx/app
|
||||||
import libnx/input
|
import libnx/input
|
||||||
|
|
@ -8,9 +8,9 @@ import libnx/input
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
initDefault()
|
initDefault()
|
||||||
discard consoleInit(nil)
|
console.init()
|
||||||
|
|
||||||
echo "\x1b[17;20HHELLO FROM NIM"
|
printAt (17, 20), "HELLO FROM NIM"
|
||||||
mainLoop:
|
mainLoop:
|
||||||
let keysDown = keysDown(Controller.P1_AUTO)
|
let keysDown = keysDown(Controller.P1_AUTO)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -354,3 +354,6 @@ template CONSOLE_CONCEAL*: int = (1 shl 7)
|
||||||
template CONSOLE_CROSSED_OUT*: int = (1 shl 8)
|
template CONSOLE_CROSSED_OUT*: int = (1 shl 8)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
search.threedmoo = "debugDevice_3DMOO"
|
||||||
|
replace.threedmoo = "debugDevice_3DMOO*"
|
||||||
|
|
|
||||||
124
src/libnx/console.nim
Normal file
124
src/libnx/console.nim
Normal file
|
|
@ -0,0 +1,124 @@
|
||||||
|
import libnx/wrapper/con
|
||||||
|
import libnx/utils
|
||||||
|
import macros, strutils
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
PrintCallback* = proc (con: pointer; c: cint): bool
|
||||||
|
|
||||||
|
#Font* = ref object
|
||||||
|
# gfx*: Buffer[uint16]
|
||||||
|
# asciiOffset*: uint16
|
||||||
|
# numChars*: uint16
|
||||||
|
|
||||||
|
Style* {.pure.} = enum
|
||||||
|
Bold = CONSOLE_COLOR_BOLD(),
|
||||||
|
Faint = CONSOLE_COLOR_FAINT(),
|
||||||
|
Italic = CONSOLE_ITALIC(),
|
||||||
|
Underline = CONSOLE_UNDERLINE(),
|
||||||
|
BlinkSlow = CONSOLE_BLINK_SLOW(),
|
||||||
|
BlinkFast = CONSOLE_BLINK_FAST(),
|
||||||
|
ColorReverse = CONSOLE_COLOR_REVERSE(),
|
||||||
|
Conceal = CONSOLE_CONCEAL(),
|
||||||
|
CrossedOut = CONSOLE_CROSSED_OUT()
|
||||||
|
|
||||||
|
Console* = ref object
|
||||||
|
pcon: ptr PrintConsole
|
||||||
|
font*: ConsoleFont
|
||||||
|
frameBuffer*: ptr UncheckedArray[uint32]
|
||||||
|
frameBuffer2*: ptr UncheckedArray[uint32]
|
||||||
|
cursorX*: int
|
||||||
|
cursorY*: int
|
||||||
|
prevCursorX*: int
|
||||||
|
prevCursorY*: int
|
||||||
|
width*: int
|
||||||
|
height*: int
|
||||||
|
windowX*: int
|
||||||
|
windowY*: int
|
||||||
|
windowWidth*: int
|
||||||
|
windowHeight*: int
|
||||||
|
tabSize*: int
|
||||||
|
fg*: int
|
||||||
|
bg*: int
|
||||||
|
flags*: set[Style]
|
||||||
|
printCharCallback*: PrintCallback
|
||||||
|
initialised*: bool
|
||||||
|
|
||||||
|
DebugDevice* {.size: sizeof(cint), pure.} = enum
|
||||||
|
Null, Service, Console, ThreeDMOO
|
||||||
|
|
||||||
|
proc toConsole(pconsole: ptr PrintConsole): Console =
|
||||||
|
result = new(Console)
|
||||||
|
result.pcon = pconsole
|
||||||
|
result.font = pconsole.font
|
||||||
|
result.cursorX = pconsole.cursorX
|
||||||
|
result.frameBuffer = cast[ptr UncheckedArray[uint32]](pconsole.frameBuffer)
|
||||||
|
result.frameBuffer2 = cast[ptr UncheckedArray[uint32]](pconsole.frameBuffer2)
|
||||||
|
result.cursorX = pconsole.cursorX
|
||||||
|
result.cursorY = pconsole.cursorY
|
||||||
|
result.prevCursorX = pconsole.prevCursorX
|
||||||
|
result.prevCursorY = pconsole.prevCursorY
|
||||||
|
result.width = pconsole.consoleWidth
|
||||||
|
result.height = pconsole.consoleHeight
|
||||||
|
result.windowX = pconsole.windowX
|
||||||
|
result.windowY = pconsole.windowY
|
||||||
|
result.windowWidth = pconsole.windowWidth
|
||||||
|
result.windowHeight = pconsole.windowHeight
|
||||||
|
result.tabSize = pconsole.tabSize
|
||||||
|
result.fg = pconsole.fg
|
||||||
|
result.bg = pconsole.bg
|
||||||
|
result.flags = {}
|
||||||
|
#result.printCharCallback = cast[PrintCallback](pconsole.PrintChar)
|
||||||
|
result.initialised = pconsole.consoleInitialised
|
||||||
|
|
||||||
|
proc setFont*(console: Console; font: ConsoleFont) =
|
||||||
|
var f = font
|
||||||
|
consoleSetFont(console.pcon, f.addr)
|
||||||
|
console.font = console.pcon.font
|
||||||
|
|
||||||
|
proc setWindow*(console: Console, x, y, width, height: int) =
|
||||||
|
console.pcon.consoleSetWindow(x.cint, y.cint, width.cint, height.cint)
|
||||||
|
console.width = console.pcon.consoleWidth
|
||||||
|
console.height = console.pcon.consoleHeight
|
||||||
|
console.windowX = console.pcon.windowX.int
|
||||||
|
console.windowY = console.pcon.windowY.int
|
||||||
|
|
||||||
|
proc getDefault*(): Console =
|
||||||
|
let pcon = consoleGetDefault()
|
||||||
|
result = pcon.toConsole()
|
||||||
|
|
||||||
|
proc select*(console: Console): Console =
|
||||||
|
consoleSelect(console.pcon).toConsole()
|
||||||
|
|
||||||
|
proc init*(console: Console = nil): Console {.discardable.} =
|
||||||
|
var newCon = console
|
||||||
|
if newCon.isNil:
|
||||||
|
newCon = new(Console)
|
||||||
|
|
||||||
|
let pcon = consoleInit(newCon.pcon)
|
||||||
|
newCon = pcon.toConsole()
|
||||||
|
return newCon
|
||||||
|
|
||||||
|
proc debugInit*(device: DebugDevice) =
|
||||||
|
if device == ThreeDMOO:
|
||||||
|
consoleDebugInit(debugDevice_3DMOO)
|
||||||
|
else:
|
||||||
|
consoleDebugInit(debugDevice(device))
|
||||||
|
|
||||||
|
proc clear*() =
|
||||||
|
consoleClear()
|
||||||
|
|
||||||
|
var printPos: tuple[row: int, col: int] = (0, 0)
|
||||||
|
|
||||||
|
proc setPrintPos*(pos: tuple[row: int, col: int]) =
|
||||||
|
printPos = pos
|
||||||
|
|
||||||
|
proc printAt*(pos: tuple[row: int, col: int], args: varargs[string, `$`]) =
|
||||||
|
setPrintPos(pos)
|
||||||
|
echo ("\x1b[$#;$#H" % [$pos[0], $pos[1]]), args.join("")
|
||||||
|
|
||||||
|
proc print*(args: varargs[string, `$`]) =
|
||||||
|
## Will print at the previously set printPos using ``printAt`` or ``setPrintPos``
|
||||||
|
## and then increment the row by one
|
||||||
|
printAt printPos, args
|
||||||
|
printPos.row += 1
|
||||||
Loading…
Add table
Add a link
Reference in a new issue