Module: TUI::Formatting

Included in:
Decorators::BaseDecorator, Screens::Chat
Defined in:
lib/tui/formatting.rb

Overview

Shared formatting helpers for timestamps and token counts. Used by both the Chat screen and client-side decorators to avoid duplicating display logic.

Instance Method Summary collapse

Instance Method Details

#format_ns_timestamp(ns) ⇒ String

Converts nanosecond-precision timestamp to human-readable HH:MM:SS.

Parameters:

  • ns (Integer, nil)

    nanosecond timestamp

Returns:

  • (String)

    formatted time, or “–:–:–” when nil



22
23
24
25
26
# File 'lib/tui/formatting.rb', line 22

def format_ns_timestamp(ns)
  return "--:--:--" unless ns

  Time.at(ns / 1_000_000_000.0).strftime("%H:%M:%S")
end

#format_token_label(tokens, estimated) ⇒ String

Formats a token count for display, with tilde prefix for estimates.

Parameters:

  • tokens (Integer, nil)

    token count

  • estimated (Boolean)

    whether the count is an estimate

Returns:

  • (String)

    formatted label, e.g. “[42 tok]” or “[~28 tok]”



12
13
14
15
16
17
# File 'lib/tui/formatting.rb', line 12

def format_token_label(tokens, estimated)
  return "" unless tokens

  label = estimated ? "~#{tokens}" : tokens.to_s
  "[#{label} tok]"
end