Implemented vertically and horizontally scrollable console-output window for agent interaction windows.

This commit is contained in:
Jakob Friedl
2025-09-11 18:18:13 +02:00
parent c2b388fbf2
commit 1a6977d52d
3 changed files with 108 additions and 29 deletions

View File

@@ -1,5 +1,7 @@
switch "o", "bin/client"
switch "d", "ImColorTextEdit"
# Select compiler
var TC = "gcc"
# var TC = "clang"

View File

@@ -1,24 +1,24 @@
[Window][Sessions [Table View]]
Pos=10,43
Size=1477,305
Size=1477,280
Collapsed=0
DockId=0x00000003,0
[Window][Listeners]
Pos=10,350
Size=1888,639
Pos=10,325
Size=1888,664
Collapsed=0
DockId=0x00000002,0
[Window][Eventlog]
Pos=1489,43
Size=409,305
Size=409,280
Collapsed=0
DockId=0x00000004,0
[Window][Dear ImGui Demo]
Pos=1489,43
Size=409,305
Size=409,280
Collapsed=0
DockId=0x00000004,1
@@ -28,16 +28,16 @@ Size=1908,999
Collapsed=0
[Window][[FACEDEAD] bob@LAPTOP-02]
Pos=10,350
Size=1888,639
Pos=10,325
Size=1888,664
Collapsed=0
DockId=0x00000002,2
[Window][[C9D8E7F6] charlie@SERVER-03]
Pos=10,350
Size=1888,639
Pos=10,325
Size=1888,664
Collapsed=0
DockId=0x00000002,0
DockId=0x00000002,2
[Window][Debug##Default]
Pos=60,60
@@ -45,31 +45,51 @@ Size=400,400
Collapsed=0
[Window][[G1H2I3J5] diana@WORKSTATION-04]
Pos=10,350
Size=1888,639
Pos=10,325
Size=1888,664
Collapsed=0
DockId=0x00000002,1
[Window][[DEADBEEF] alice@DESKTOP-01]
Pos=10,350
Size=1888,639
Pos=10,325
Size=1888,664
Collapsed=0
DockId=0x00000002,1
[Window][Example: Console]
Pos=10,426
Size=1888,563
Collapsed=0
DockId=0x00000002,1
[Window][Example: Assets Browser]
Pos=60,60
Size=800,480
Collapsed=0
[Window][Example: Documents]
Pos=186,108
Size=997,993
Collapsed=0
[Table][0x32886A44,8]
Column 0 Weight=0.6570
Column 1 Weight=0.9786
Column 2 Weight=0.6570
Column 3 Weight=1.1429
Column 4 Weight=1.5466
Column 5 Weight=1.1429
Column 6 Weight=0.3285
Column 7 Weight=1.5466
Column 0 Weight=0.6522
Column 1 Weight=0.9755
Column 2 Weight=0.6522
Column 3 Weight=0.9639
Column 4 Weight=1.7316
Column 5 Weight=1.1486
Column 6 Weight=0.3290
Column 7 Weight=1.5469
[Table][0xB6880529,2]
RefScale=27
Column 0 Sort=0v
[Docking][Data]
DockSpace ID=0x85940918 Window=0x260A4489 Pos=10,43 Size=1888,946 Split=Y
DockNode ID=0x00000001 Parent=0x85940918 SizeRef=1024,159 Split=X
DockNode ID=0x00000001 Parent=0x85940918 SizeRef=1024,280 Split=X
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=613,159 CentralNode=1 Selected=0x61E02D75
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=409,159 Selected=0x5E5F7166
DockNode ID=0x00000002 Parent=0x85940918 SizeRef=1024,639 Selected=0x8D780333
DockNode ID=0x00000002 Parent=0x85940918 SizeRef=1024,664 Selected=0x8D780333

View File

@@ -1,4 +1,4 @@
import strformat
import strformat, strutils
import imguin/[cimgui, glfw_opengl, simple]
import ../utils/appImGui
import ../../common/[types]
@@ -7,19 +7,76 @@ type
ConsoleComponent* = ref object of RootObj
agent: Agent
showConsole*: bool
inputBuffer: string
consoleEntries: seq[string]
proc Console*(agent: Agent): ConsoleComponent =
result = new ConsoleComponent
result.agent = agent
result.showConsole = true
result.consoleEntries = @[
"a",
"a",
"a",
"a",
"aAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"a",
"a",
"a",
"a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a"
]
proc findLongestLength(text: string): float32 =
var maxWidth = 0.0f
for line in text.splitLines():
let line_cstring = line.cstring
var textSizeOut: ImVec2
igCalcTextSize(addr textSizeOut, line_cstring, nil, false, -1.0f)
if textSizeOut.x > maxWidth:
maxWidth = textSizeOut.x
return maxWidth
proc draw*(component: ConsoleComponent) =
igSetNextWindowSize(vec2(800, 600), ImGuiCond_Once.int32)
# var showComponent = component.showConsole
igBegin(fmt"[{component.agent.agentId}] {component.agent.username}@{component.agent.hostname}", addr component.showConsole, 0)
defer: igEnd()
igText(component.agent.agentId)
# Console text section
let footerHeight = igGetStyle().ItemSpacing.y + igGetFrameHeightWithSpacing()
let buffer = component.consoleEntries.join("\n") & '\0'
# Push styles to hide the Child's background and scrollbar background.
igPushStyleColor_Vec4(ImGuiCol_FrameBg.int32, vec4(0.0f, 0.0f, 0.0f, 0.0f))
igPushStyleColor_Vec4(ImGuiCol_ScrollbarBg.int32, vec4(0.0f, 0.0f, 0.0f, 0.0f))
# component.showConsole = showComponent
if igBeginChild_Str("##Console", vec2(-0.99f, -footerHeight), ImGuiChildFlags_NavFlattened.int32, ImGuiWindowFlags_HorizontalScrollbar.int32):
# Manually handle horizontal scrolling with the mouse wheel/touchpad
let io = igGetIO()
if io.MouseWheelH != 0:
let scroll_delta = io.MouseWheelH * igGetScrollX() * 0.5
igSetScrollX_Float(igGetScrollX() - scroll_delta)
if igGetScrollX() == 0:
igSetScrollX_Float(1.0f) # This is required to prevent the horizontal scrolling from snapping in
# Retrieve the length of the longes console entry
let width = findLongestLength(buffer)
# Set the Text edit background color and make it visible.
igPushStyleColor_Vec4(ImGuiCol_FrameBg.int32, vec4(0.1f, 0.1f, 0.1f, 1.0f))
igPushStyleColor_Vec4(ImGuiCol_ScrollbarBg.int32, vec4(0.1f, 0.1f, 0.1f, 1.0f))
discard igInputTextMultiline("##ConsoleText", buffer, cast[csize_t](buffer.len()), vec2(width, -1.0f), ImGui_InputTextFlags_ReadOnly.int32 or ImGui_InputTextFlags_AllowTabInput.int32, nil, nil)
igPopStyleColor(2)
igPopStyleColor(2)
igEndChild()
igSeparator()
# Input field
igSetNextItemWidth(-1.0f)
let inputFlags = ImGuiInputTextFlags_EnterReturnsTrue.int32 or ImGuiInputTextFlags_EscapeClearsAll.int32 or ImGuiInputTextFlags_CallbackCompletion.int32 or ImGuiInputTextFlags_CallbackHistory.int32
if igInputText("##Input", component.inputBuffer, 256, inputFlags, nil, nil):
discard
igSetItemDefaultFocus()