Made timestamps toggle-able in eventlog window.
This commit is contained in:
@@ -266,19 +266,10 @@ proc draw*(component: ConsoleComponent, ws: WebSocket) =
|
|||||||
|
|
||||||
let command = ($(addr component.inputBuffer[0])).strip()
|
let command = ($(addr component.inputBuffer[0])).strip()
|
||||||
if not command.isEmptyOrWhitespace():
|
if not command.isEmptyOrWhitespace():
|
||||||
|
|
||||||
component.addItem(LOG_COMMAND, command)
|
component.addItem(LOG_COMMAND, command)
|
||||||
|
|
||||||
# For testing
|
# Send command to team server
|
||||||
# component.addItem(LOG_ERROR, "error message")
|
|
||||||
# component.addItem(LOG_SUCCESS, "success message")
|
|
||||||
# component.addItem(LOG_INFO, "info message")
|
|
||||||
# component.addItem(LOG_WARNING, "warning message")
|
|
||||||
# component.addItem(LOG_OUTPUT, "error message\nLong output\n\tindented output\nasdasd")
|
|
||||||
|
|
||||||
# TODO: Handle command execution
|
|
||||||
# console.handleCommand(command)
|
|
||||||
ws.send("CMD:" & component.agent.agentId & ":" & command)
|
|
||||||
|
|
||||||
# Add command to console history
|
# Add command to console history
|
||||||
component.history.add(command)
|
component.history.add(command)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ type
|
|||||||
title: string
|
title: string
|
||||||
log*: ConsoleItems
|
log*: ConsoleItems
|
||||||
textSelect: ptr TextSelect
|
textSelect: ptr TextSelect
|
||||||
|
showTimestamps: bool
|
||||||
|
|
||||||
proc getText(item: ConsoleItem): cstring =
|
proc getText(item: ConsoleItem): cstring =
|
||||||
if item.timestamp > 0:
|
if item.timestamp > 0:
|
||||||
@@ -37,6 +38,7 @@ proc Eventlog*(title: string): EventlogComponent =
|
|||||||
result.log = new ConsoleItems
|
result.log = new ConsoleItems
|
||||||
result.log.items = @[]
|
result.log.items = @[]
|
||||||
result.textSelect = textselect_create(getLineAtIndex, getNumLines, cast[pointer](result.log), 0)
|
result.textSelect = textselect_create(getLineAtIndex, getNumLines, cast[pointer](result.log), 0)
|
||||||
|
result.showTimestamps = false
|
||||||
|
|
||||||
#[
|
#[
|
||||||
API to add new log entry
|
API to add new log entry
|
||||||
@@ -45,7 +47,7 @@ proc addItem*(component: EventlogComponent, itemType: LogType, data: string, tim
|
|||||||
|
|
||||||
for line in data.split("\n"):
|
for line in data.split("\n"):
|
||||||
component.log.items.add(ConsoleItem(
|
component.log.items.add(ConsoleItem(
|
||||||
timestamp: if itemType == LOG_OUTPUT: 0 else: timestamp,
|
timestamp: timestamp,
|
||||||
itemType: itemType,
|
itemType: itemType,
|
||||||
text: line
|
text: line
|
||||||
))
|
))
|
||||||
@@ -53,8 +55,8 @@ proc addItem*(component: EventlogComponent, itemType: LogType, data: string, tim
|
|||||||
#[
|
#[
|
||||||
Drawing
|
Drawing
|
||||||
]#
|
]#
|
||||||
proc print(item: ConsoleItem) =
|
proc print(component: EventlogComponent, item: ConsoleItem) =
|
||||||
if item.timestamp > 0:
|
if (item.itemType != LOG_OUTPUT) and component.showTimestamps:
|
||||||
let timestamp = item.timestamp.fromUnix().format("dd-MM-yyyy HH:mm:ss")
|
let timestamp = item.timestamp.fromUnix().format("dd-MM-yyyy HH:mm:ss")
|
||||||
igTextColored(vec4(0.6f, 0.6f, 0.6f, 1.0f), fmt"[{timestamp}]".cstring)
|
igTextColored(vec4(0.6f, 0.6f, 0.6f, 1.0f), fmt"[{timestamp}]".cstring)
|
||||||
igSameLine(0.0f, 0.0f)
|
igSameLine(0.0f, 0.0f)
|
||||||
@@ -91,8 +93,14 @@ proc draw*(component: EventlogComponent, showComponent: ptr bool) =
|
|||||||
if igBeginChild_Str("##Log", vec2(-1.0f, -1.0f), childWindowFlags, ImGuiWindowFlags_HorizontalScrollbar.int32):
|
if igBeginChild_Str("##Log", vec2(-1.0f, -1.0f), childWindowFlags, ImGuiWindowFlags_HorizontalScrollbar.int32):
|
||||||
# Display eventlog items
|
# Display eventlog items
|
||||||
for item in component.log.items:
|
for item in component.log.items:
|
||||||
item.print()
|
component.print(item)
|
||||||
|
|
||||||
|
# Right click context menu to toggle timestamps in eventlog
|
||||||
|
if igBeginPopupContextWindow("EventlogSettings", ImGui_PopupFlags_MouseButtonRight.int32):
|
||||||
|
if igCheckbox("Show timestamps", addr component.showTimestamps):
|
||||||
|
igCloseCurrentPopup()
|
||||||
|
igEndPopup()
|
||||||
|
|
||||||
component.textSelect.textselect_update()
|
component.textSelect.textselect_update()
|
||||||
|
|
||||||
# Auto-scroll to bottom
|
# Auto-scroll to bottom
|
||||||
|
|||||||
Reference in New Issue
Block a user