added some node info to UI
This commit is contained in:
parent
64bd152416
commit
9378c995f9
53
display.nim
53
display.nim
|
@ -1,7 +1,9 @@
|
|||
import strformat, strutils
|
||||
|
||||
import illwill
|
||||
|
||||
import config, module
|
||||
import renderer
|
||||
import config, peer, topic
|
||||
import node
|
||||
|
||||
type
|
||||
ViewType* = enum
|
||||
|
@ -67,6 +69,30 @@ proc toggleHelpView*() =
|
|||
|
||||
var gTerminalBuffer: TerminalBuffer
|
||||
|
||||
proc drawNodeState*(tb: var TerminalBuffer, ns: NodeState) =
|
||||
const
|
||||
X1 = SCREEN_X_PAD + 1
|
||||
Y1 = SCREEN_Y_PAD + 0
|
||||
COL1_X = X1
|
||||
COL1_X_VAL = COL1_X + 10
|
||||
|
||||
# Node Status Column
|
||||
var y = Y1
|
||||
|
||||
tb.setColor(gCurrTheme.text)
|
||||
tb.write(COL1_X, y, fmt"Status:")
|
||||
tb.setColor(gCurrTheme.textHi)
|
||||
tb.write(COL1_X_VAL, y, fmt"{ns.connectionStatus}")
|
||||
inc(y)
|
||||
|
||||
tb.setColor(gCurrTheme.text)
|
||||
tb.write(COL1_X, y, fmt"Num Peers:")
|
||||
tb.setColor(gCurrTheme.textHi)
|
||||
tb.write(COL1_X_VAL, y, fmt"{ns.numPeers}")
|
||||
|
||||
inc(y)
|
||||
|
||||
|
||||
proc drawMainView(tb: var TerminalBuffer) =
|
||||
if tb.height < 9: return
|
||||
|
||||
|
@ -112,28 +138,6 @@ proc drawMainView(tb: var TerminalBuffer) =
|
|||
tb.setColor(gCurrTheme.border)
|
||||
tb.write(bb)
|
||||
|
||||
proc drawNodeState(tb: var TerminalBuffer, ns: NodeState) =
|
||||
const WIDTH = 70
|
||||
|
||||
# Channels Column
|
||||
const
|
||||
x1 = SCREEN_X_PAD
|
||||
y1 = 2
|
||||
x2 = x1 + WIDTH
|
||||
y2 = 70
|
||||
|
||||
var bb = newBoxBuffer(tb.width, tb.height)
|
||||
|
||||
# Draw border
|
||||
bb.drawVertLine(x1, y1, y2)
|
||||
bb.drawVertLine(x2, y1, y2)
|
||||
bb.drawHorizLine(x1, x2, y1)
|
||||
bb.drawHorizLine(x1, x2, y2)
|
||||
|
||||
tb.setColor(gCurrTheme.border)
|
||||
tb.write(bb)
|
||||
|
||||
|
||||
|
||||
var gHelpViewText: TerminalBuffer
|
||||
|
||||
|
@ -259,6 +263,7 @@ proc drawScreen(tb: var TerminalBuffer, ns: NodeState) =
|
|||
# drawNodeState(tb, ns)
|
||||
drawMainView(tb)
|
||||
drawStatusLine(tb)
|
||||
drawNodeState(tb, ns)
|
||||
|
||||
let viewHeight = max(tb.height - TOP_Y_PAD - 3, 0)
|
||||
|
||||
|
|
22
main.nim
22
main.nim
|
@ -1,18 +1,16 @@
|
|||
import logging, math, os, strformat, strutils
|
||||
import logging, os
|
||||
|
||||
import illwill
|
||||
|
||||
import config
|
||||
import display
|
||||
# import loader
|
||||
import module
|
||||
import renderer
|
||||
import node
|
||||
|
||||
proc nodeQuitProc() {.noconv.} =
|
||||
illwillDeinit()
|
||||
|
||||
proc startNode(config: Config, module: Module) =
|
||||
var ns = initNodeState(config, module)
|
||||
proc startNode(config: Config) =
|
||||
var ns = initNodeState(config)
|
||||
|
||||
system.addQuitProc(nodeQuitProc)
|
||||
|
||||
|
@ -24,13 +22,6 @@ proc startNode(config: Config, module: Module) =
|
|||
else:
|
||||
illwillInit(fullscreen = false)
|
||||
|
||||
var
|
||||
currPattern = 0
|
||||
currRow = 0
|
||||
lastPattern = -1
|
||||
lastRow = -1
|
||||
|
||||
|
||||
while true:
|
||||
let key = getKey()
|
||||
case key:
|
||||
|
@ -109,9 +100,6 @@ proc main() =
|
|||
elif config.suppressWarnings:
|
||||
setLogFilter(lvlError)
|
||||
|
||||
# Load module
|
||||
var module: Module
|
||||
|
||||
startNode(config, module)
|
||||
startNode(config)
|
||||
|
||||
main()
|
||||
|
|
14
module.nim
14
module.nim
|
@ -1,14 +0,0 @@
|
|||
type
|
||||
Module* = ref object
|
||||
moduleType*: ModuleType
|
||||
numChannels*: Natural
|
||||
useAmigaLimits*: bool
|
||||
|
||||
ModuleType* = enum
|
||||
mtFastTracker,
|
||||
mtOctaMED,
|
||||
mtOktalyzer,
|
||||
mtProTracker,
|
||||
mtSoundTracker,
|
||||
mtStarTrekker,
|
||||
mtTakeTracker
|
|
@ -0,0 +1,38 @@
|
|||
import config
|
||||
import peer, topic
|
||||
|
||||
type
|
||||
NodeState* = object
|
||||
# These two are set when initialising the object and should only read
|
||||
# from after that.
|
||||
config*: Config
|
||||
connectionStatus*: ConnectionType
|
||||
|
||||
# set of peers the node is connected to
|
||||
peers*: seq[Peer]
|
||||
numPeers*: Natural
|
||||
|
||||
|
||||
# The current subscribed to channels
|
||||
topics*: seq[Topic]
|
||||
numTopics*: Natural
|
||||
|
||||
ConnectionType* = enum
|
||||
ctDisconnected,
|
||||
ctConnected,
|
||||
ctConnecting
|
||||
|
||||
proc initNodeState*(config: Config): NodeState =
|
||||
var ns: NodeState
|
||||
ns.config = config
|
||||
|
||||
ns.topics = newSeq[Topic]()
|
||||
for tp in 0..ns.numTopics:
|
||||
var top = newTopic()
|
||||
ns.topics.add(top)
|
||||
|
||||
ns.peers = newSeq[Peer]()
|
||||
for pr in 1..ns.numPeers:
|
||||
var peer = newPeer()
|
||||
ns.peers.add(peer)
|
||||
result = ns
|
|
@ -0,0 +1,13 @@
|
|||
type
|
||||
Peer* = ref object
|
||||
peerType*: PeerType
|
||||
enode*: string
|
||||
|
||||
PeerType* = enum
|
||||
ptWaku,
|
||||
ptWhisper,
|
||||
ptMailserver,
|
||||
ptLight
|
||||
|
||||
proc newPeer*(): Peer =
|
||||
result = new Peer
|
34
renderer.nim
34
renderer.nim
|
@ -1,34 +0,0 @@
|
|||
import math, strformat
|
||||
|
||||
import config
|
||||
import module
|
||||
|
||||
type
|
||||
NodeState* = object
|
||||
# These two are set when initialising the object and should only read
|
||||
# from after that.
|
||||
config*: Config
|
||||
module*: Module
|
||||
|
||||
# The mute state of the channels can be set from the outside
|
||||
channels*: seq[Channel]
|
||||
|
||||
Channel* = object
|
||||
# Can be set from the outside to mute/unmute channels
|
||||
state*: ChannelState
|
||||
|
||||
ChannelState* = enum
|
||||
csPlaying, csMuted, csDimmed
|
||||
|
||||
proc initNodeState*(config: Config, module: Module): NodeState =
|
||||
var ns: NodeState
|
||||
ns.config = config
|
||||
ns.module = module
|
||||
|
||||
# ns.channels = newSeq[Channel]()
|
||||
# for ch in 0..<module.numChannels:
|
||||
# var chan = initChannel()
|
||||
# ns.channels.add(chan)
|
||||
|
||||
|
||||
result = ns
|
Loading…
Reference in New Issue