Skip to content

feat(docs): add --text-color flag and docs color subcommand#412

Open
sixel-et wants to merge 2 commits intosteipete:mainfrom
sixel-et:feat/text-color
Open

feat(docs): add --text-color flag and docs color subcommand#412
sixel-et wants to merge 2 commits intosteipete:mainfrom
sixel-et:feat/text-color

Conversation

@sixel-et
Copy link

@sixel-et sixel-et commented Mar 4, 2026

Summary

  • Adds --text-color flag to gog docs write, gog docs insert, and gog docs update commands
  • Accepts named colors (red, blue, green, purple, teal, etc.) and hex colors (#RRGGBB, #RGB, RRGGBB)
  • Adds new gog docs color subcommand for applying color to existing text in a document

Usage

--text-color flag (new text)

# Named color
gog docs write <docId> --text "Hello world" --append --text-color blue

# Hex color
gog docs insert <docId> --text "Note: " --text-color "#FF6600"

docs color subcommand (existing text)

# Color specific text
gog docs color <docId> "text to find" red

# Color entire paragraph containing match
gog docs color <docId> "text to find" "#a64d79" --paragraph

# Color all occurrences
gog docs color <docId> "warning" orange --all

Implementation

--text-color flag:

  • ParseTextColor() in docs_formatter.go — parses named colors (15 built-in) and hex codes
  • BuildColorRequest() — creates UpdateTextStyleRequest with foregroundColor
  • Color applied via BatchUpdate in the same request as text insertion (InsertText + UpdateTextStyle)
  • Works with --append, --replace, and index-based insertion

docs color subcommand:

  • Fetches document structure via Documents.Get() to obtain correct structural indices
  • Walks paragraph elements to find matching text
  • Applies UpdateTextStyleRequest via BatchUpdate
  • --paragraph flag colors the entire containing paragraph, not just the matched substring
  • --all flag colors all occurrences, not just the first

Tests

  • TestParseTextColor_NamedColors — 7 cases including case insensitivity
  • TestParseTextColor_HexColors — 8 cases including 3-digit, 6-digit, no-hash, invalid
  • TestBuildColorRequest — verifies range and foreground color fields
  • All 14 existing test packages pass

Motivation

Collaborative document editing where multiple contributors need visually distinct text. We use this for a multi-session AI writing workflow where each contributor writes in a different color.

sixel-et and others added 2 commits March 4, 2026 07:07
Adds the ability to set foreground text color when writing or inserting
text into Google Docs. Accepts named colors (red, blue, green, etc.) and
hex colors (#RRGGBB, #RGB). The color is applied as an UpdateTextStyleRequest
in the same batch as the text insertion.

Usage:
  gog docs write <docId> --text "hello" --text-color blue
  gog docs insert <docId> "note" --text-color "#FF6600"
  gog docs update <docId> --text "text" --text-color red

Includes ParseTextColor() and BuildColorRequest() helpers, plus unit tests
for named colors, hex parsing, and request construction.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Applies foreground color to text found in a Google Doc using the
Docs API structural indices (not plain text offsets). Supports
--paragraph flag to color the entire containing paragraph.

Usage:
  gog docs color <docId> "text to find" <color>
  gog docs color <docId> "text" "#a64d79" --paragraph
  gog docs color <docId> "text" blue --all

This solves the problem where find-replace loses color: you can
find-replace first, then color the result.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sixel-et sixel-et changed the title feat(docs): add --text-color flag for write, insert, update feat(docs): add --text-color flag and docs color subcommand Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant