diff --git a/display.nim b/display.nim index 0ef6670..c99ff7f 100644 --- a/display.nim +++ b/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) diff --git a/main b/main index 28c1ec0..ad4af4c 100755 Binary files a/main and b/main differ diff --git a/main.nim b/main.nim index e91634c..71197ac 100644 --- a/main.nim +++ b/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() diff --git a/module.nim b/module.nim deleted file mode 100644 index 743bf3d..0000000 --- a/module.nim +++ /dev/null @@ -1,14 +0,0 @@ -type - Module* = ref object - moduleType*: ModuleType - numChannels*: Natural - useAmigaLimits*: bool - - ModuleType* = enum - mtFastTracker, - mtOctaMED, - mtOktalyzer, - mtProTracker, - mtSoundTracker, - mtStarTrekker, - mtTakeTracker diff --git a/node.nim b/node.nim new file mode 100644 index 0000000..67875b9 --- /dev/null +++ b/node.nim @@ -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 \ No newline at end of file diff --git a/peer.nim b/peer.nim new file mode 100644 index 0000000..6881089 --- /dev/null +++ b/peer.nim @@ -0,0 +1,13 @@ +type + Peer* = ref object + peerType*: PeerType + enode*: string + + PeerType* = enum + ptWaku, + ptWhisper, + ptMailserver, + ptLight + +proc newPeer*(): Peer = + result = new Peer \ No newline at end of file diff --git a/renderer.nim b/renderer.nim deleted file mode 100644 index 3a2914c..0000000 --- a/renderer.nim +++ /dev/null @@ -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..