Skip to content
devwangtingPublic

About

A terminal Source Insight-style C/C++ editor and source browser in C11. AI-generated. 终端源码浏览器:五面板 TUI、项目索引、调用链,无第三方依赖。

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

31 Commits

Folders and files

Repository files navigation

si-c

A terminal C/C++ editor and source browser that emulates the Source Insight workflow

C11 Platform Dependencies AI Generated

Important

AI-generated notice: The source code, tests, and documentation of this project were generated by an AI coding assistant (OpenCode / DeepSeek). Humans defined the requirements, reviewed the results, and published the repository. This is an independent implementation in the style of Source Insight; it is not an official Source Insight product and is not affiliated with Source Insight. See AI_GENERATED.md for details.

Project scope

si-c is not a complete replacement for Source Insight; it is a terminal prototype you can build, run, edit, and navigate. It brings Source Insight's most common "read code / find definitions / inspect call relationships" workflow into the terminal:

  • left: functions, macros, types, and global variables of the current file;
  • center: the code editor;
  • bottom: where a symbol is actually defined and what it looks like;
  • right: project files and call chains;
  • every panel can be operated with the mouse, keyboard, or splitter bars.

The program depends only on C11 + POSIX + ANSI escape sequences; it does not use ncurses, SQLite, LSP, or any third-party library. A terminal of at least 100x30 is recommended, preferably with 256 colors; 16-color terminals degrade automatically.

What it actually does

  • Five-panel TUI: FILE OUTLINE, editor, SYMBOL INFO / CODE, PROJECT FILES, CALL FLOW.
  • Project-wide index: recursively scans C/C++ files and recognizes functions, prototypes, macros, structs/unions/enums/classes/namespaces, typedefs, global variables, enum constants, and struct members.
  • Project symbol search: Ctrl+P live-filters symbols across the project.
  • Project text search: Alt/Option+G searches source files on disk and lists the matches.
  • Jump to definition / find references: F12 / Shift+F12, jumping to the real file and line.
  • Call chains: builds a graph from name(...) call expressions in function bodies, and marks positions where a function name appears as a value with [ref] (for example signal(SIGINT, handler), &handler, and std::thread arguments), so signal registration, callbacks, and function-pointer assignments also show up in CALL FLOW; supports multiple call levels, cycle detection, and choosing among same-named functions. Boxes show Class::method qualified names; same-named methods prefer the explicit qualifier at the call site, then the caller's class.
  • Global variable usage table: shows which functions use a global variable and where.
  • Symbol source preview: the CODE panel shows the original source at the definition with line numbers and syntax highlighting.
  • Editing: UTF-8, undo/redo, auto-indent, Tab-to-spaces, find, mouse drag selection, Ctrl+C / Ctrl+V, and the OSC52 terminal clipboard.
  • Variable completion: typing an identifier automatically lists the current function's locals/parameters, globals, functions, macros, types, and keywords; typing . / -> lists struct/class members and supports chained access; typing :: lists a class's static members, member functions, and nested types, including qualified names such as Thing::Inner:: and demo_ns::NsThing::. C++ class members include data members, member functions, static members, and nested types; inherited members and this-> are also listed. Typing a bare identifier inside a class method also lists members of the current class and its bases (same-named locals take precedence). auto locals are inferred from Type(), Type{}, variable copies, &var, &ref, common literals, and the return types of ordinary/member functions; locals qualified with constexpr / thread_local are recognized as well. Template instantiations such as Box<int> fall back to Box for member lookup, and using Alias = Type; aliases expand to the target type. Tab/Enter accepts, Esc dismisses the current word; a single mouse click highlights, a double click accepts, and the wheel scrolls.
  • Code formatting: F6, built-in astyle --style=ansi-style formatting that preserves preprocessor lines.
  • Project compilation: Ctrl+F5 builds the whole project. A project Makefile is used when present; otherwise the C/C++ compiler is detected from PATH, every source file is compiled into build/obj/, and the program is linked to build/<project-name>. A centered window shows the live command output, supports scrolling, and stays open after success or failure until you press Enter/Esc; Esc cancels a running build.
  • Compile menu: the top-level Compile menu provides Compile Project (Ctrl+F5). Quit (Ctrl+Q) remains in the Help menu.
  • Variable highlighting: F8 highlights all occurrences of the current variable in the visible area and the CODE panel.
  • Themes and mouse: dark/light themes, SGR mouse click, drag selection, wheel, and four draggable splitters.
  • Project cache: .si-index stores files, symbols, call edges, and variable-use relations, validated by file size and mtime to avoid repeated indexing.
  • Recent projects: launched without arguments, shows a list of recently opened/created projects instead of opening the last project automatically.
  • Command-line batch mode: --index, --files, --symbols, --refs, --search.
  • macOS Option key support: Option acts as Alt, and the symbols produced by the default keyboard layout are recognized.

Interface

 SI-C  demo  [main.c]
 FILE OUTLINE              │ main.c                      │ PROJECT FILES (3)
 macro  GREETING        L4 │  1 │ #include <stdio.h>      │> main.c
 struct Point           L6 │  2 │ #include "util.h"       │  util.c
 typedef Point          L9 │ ...│                         │  util.h
 fn     helper         L11 │ 18 │     Point p = {1, 2};   │
 fn     main           L16 │ 19 │     printf(...);        │
 var    global_counter L23 │ 20 │     return add(...);    │
                           │ CODE  p  main.c:18 ─────────│ CALL FLOW  helper ─────
                           │ 17 │ {                      │ static int helper  main.c:11
                           │ 18 │     Point p = {1, 2};   │ CALLERS (1)
                           │ 19 │     printf(...);        │ ↳ int main(void)   main.c:16
                           │ 20 │     return add(...);    │
 F2 outline  ^F3 flow  ^F4 editor  F3 next  F4 prev  F7 files  ^R context  ^F find  ^S save  F1 help
 Ln 18, Col 11  saved  fn:main

All four splitters can be dragged with the mouse: left column/editor, editor/right column, editor/CODE, and file list/CALL FLOW. Hovering over a splitter shows ↔ / ↕ handles and the current ratio.

Relationship to Source Insight

Source Insight si-c
Project Files PROJECT FILES (top right)
Symbol Window FILE OUTLINE (left)
Context Window SYMBOL INFO / CODE (bottom center)
Relation Window CALL FLOW (bottom right)
Jump to Definition F12
Find References Shift+F12
Project Symbol Lookup Ctrl+P
Project-wide Search Alt/Option+G
Syntax Formatting F6
Rebuild Project Ctrl+F5
Browsing History Alt/Option+←/→
Multiple Files open file tabs + F9 / Shift+F9

Build and run

All you need is a C compiler and make.

Linux

sudo apt install build-essential      # Debian / Ubuntu
make -j
make test
./si examples/demo

On other distributions, install gcc (or clang) and make. The program does not link against ncurses and has no runtime dependencies.

macOS

make -j
make test
./si examples/demo

The Makefile automatically adds -D_DARWIN_C_SOURCE on macOS. If you set CPPFLAGS manually, keep -D_POSIX_C_SOURCE=200809L -D_DARWIN_C_SOURCE -Isrc. Intel and Apple Silicon are supported; the installer build in this repository uses a universal binary.

Install system-wide

./install.sh                          # build and install to /usr/local/bin/si
PREFIX=$HOME/.local ./install.sh      # install to the user directory

The script builds first, then calls sudo as needed to write to the target directory; in non-interactive environments, set SUDO_PASSWORD. After installation, si can be run from any directory.

Open a project

./si /path/to/project        # open a directory and index it recursively
./si /path/to/project/a.c    # open a file and index its directory
./si                         # show recent projects; do not open automatically

Running ./si without arguments does not automatically open the last project; it shows the recent project list in an empty workspace. If no project has ever been opened or created, the list is empty; press Ctrl+O to open a directory or Ctrl+N to create a project. When a path is passed explicitly, it is opened directly and added to recent projects.

The recent project list supports Up/Down to select, Enter to open, Ctrl+O to browse for a directory, Ctrl+N to create a project, and Esc to close the list.

Command-line batch mode

When not entering the TUI, you can query the index directly, which is useful for scripts or quick checks:

./si --index .
./si --files .
./si --symbols=main .
./si --refs=vec_push .
./si --search="VEC_OK" .
./si --theme=light .
Option Purpose
--index Index the project, print file/symbol statistics, then exit
--files List source files in the project
--symbols[=PATTERN] List symbols, with case-insensitive substring filtering
--refs=NAME List references to NAME
--search=TEXT Search project text
--theme=dark|light Select the dark or light theme
--version Print the version
--help Show command-line help

--refs / --search read saved content from disk and do not include unsaved buffers.

Keyboard shortcuts

Panels and navigation

Key Action
F1 / Ctrl+H Help
F2 / Ctrl+B Focus the file outline on the left
Ctrl+F3 Focus CALL FLOW in the bottom right
Ctrl+F4 / Esc Focus the editor
F7 Focus the PROJECT FILES list in the top right
Tab / Shift+Tab Cycle through the five panels
Ctrl+T Cycle focus
Alt/Option+M Open the top drop-down menu
Alt/Option+R Rebuild function/variable/call relation tables
F5 Rescan the project and rebuild the index
Ctrl+F5 Compile the whole project (Compile menu)
F10 / Ctrl+F10 Navigate back / forward
Alt/Option+←/→ Navigate back / forward
F9 / Shift+F9 Next / previous open file
Ctrl+Q Quit (asks first if there are unsaved files)

Search and jump

Key Action
F12 Jump to the definition of the identifier under the cursor
Shift+F12 Find references to the identifier under the cursor
Ctrl+P Project-wide symbol search (live filtering)
Alt/Option+G Project-wide text search
Ctrl+G / Ctrl+L Go to a specific line
Ctrl+R Show the current symbol's context/call relations in the right column
Ctrl+O Open a project directory
Ctrl+N Create a new project
Enter Open a file / jump to the selected symbol

Editing and display

Key Action
Ctrl+S Save the current file
Ctrl+A Save all files
Ctrl+Z / Ctrl+Y Undo / redo
Ctrl+F Find in file / find next
F3 Find next using the last search (current file)
F4 Find previous using the last search (current file)
F8 Highlight/unhighlight the current variable
Shift+F8 Find previous
F6 Format code (ANSI style)
Ctrl+K / Ctrl+U Delete to end of line / delete to start of line
Ctrl+←/→ Move by word
Ctrl+Home/End Start / end of file
Mouse drag + Ctrl+C/V Select text, copy, paste
Mouse wheel / PgUp / PgDn Scroll the CODE panel or lists

Completion list

Candidates appear automatically when you type an identifier, but a unique candidate is not accepted automatically. While the list is active:

Key/mouse Action
Up / Down Move the selection up/down
PgUp / PgDn / Home / End Page / first item / last item
Tab / Enter Accept the selected item
Esc Close the list and stop auto-matching the current word
Single click Highlight the item only
Double-click the same item Accept it
Mouse wheel Scroll the candidate list

Candidates come from locals/parameters visible in the current function, globals, functions, macros, types, C/C++ keywords, and built-in types; after typing . or ->, only struct/union/class members are listed, and chained access such as a.b.c and a.b->c is supported. Completion is not triggered in comments, strings, or preprocessor lines.

The Option key on macOS

Mac keyboards have no Alt key; Option (⌥) is the equivalent. The program maps the symbols produced by Option combined with letters/digits (for example Option+R = ®, Option+G = ©, Option+M = µ, Option+1 = ¡) to the corresponding shortcuts, and Option+←/→ also navigates back/forward.

On an ABC/US keyboard, Option+E and Option+I are dead keys (they wait for another character to produce an accent). Use Option+Shift+E / Option+Shift+I instead, or Option+3 / Option+5. Alternatively, enable Use Option as Meta Key in Terminal settings; after that, all Option combinations are sent directly as Alt combinations.

Feature details

Project index

When starting or opening a project, si-c recursively scans .c/.h/.cc/.cpp/.cxx/.hpp/.hh/.hxx/.inl and other files, skipping directories such as .git, node_modules, build, out, target, and dist. The indexer uses a lightweight lexer with no third-party dependencies, skips comments and strings, and recognizes:

  • function definitions / function prototypes
  • struct / union / enum / class / namespace
  • typedef (including function-pointer typedefs)
  • #define macros
  • file-scope global variables
  • enum constants
  • struct/class members

Index results are sorted by file and line number. The parser is heuristic: it does not expand macros or build a complete AST; this is the trade-off between fast browsing and full semantic analysis.

Project cache and restoration

  • After the first index, a hidden .si-index file is written to the project root, storing files, symbols, call edges, and variable-use tables.
  • When the project is opened again, the cache is loaded first; if sources changed, validation by file size and modification time triggers an automatic rebuild.
  • A LOADING progress window is shown during startup and cache loading.
  • Running ./si without arguments reads recently opened/created projects from ~/.si-c-state and shows the list; it does not open a project automatically.
  • recent= lines in ~/.si-c-state store project history, ordered by most recent use; a legacy root= is automatically migrated as the first history entry.
  • Adding or removing files does not trigger an incremental scan; press F5 to force a rebuild.

Large projects

  • Project files and symbols are capped at 20,000 files and 200,000 symbols.
  • When there are more than 2,000 files or the directory depth exceeds 12, the call graph/variable relation tables are not built automatically at startup; a LARGE PROJECT prompt is shown instead:
    • Enter / Esc: browse the code first without building the relation tables;
    • Alt/Option+R: build immediately, then show a confirmation window when done.
  • Scanning/parsing progress is shown during indexing; Esc / Ctrl+C cancels.

Call chains

Move the cursor onto a function or variable name in the editor, and CALL FLOW in the bottom-right shows:

  • the target function/variable on the left;
  • callers grow to the right, with multiple callers of the same function stacked vertically;
  • each box corresponds to a real call site; Enter jumps to the caller(...) line;
  • boxes use Class::method / ns::Class::method qualified names to avoid confusion between same-named methods;
  • at most 8 levels and 200 nodes, with cycle detection;
  • same-named functions trigger a SELECT DEFINITION chooser;
  • pressing Ctrl+R directly also refreshes the context of the current symbol.

When the relation tables have not been built, CALL FLOW shows RELATION INDEX NOT BUILT and Press Alt/Option+R to build call/variable tables; it does not rebuild silently.

Symbol info / CODE panel

  • Shows the current symbol's kind, defining file, defining line, and source snippet.
  • The file location and identifiers in the defining code use a highlighted background.
  • Long functions can be scrolled with PgUp / PgDn / the wheel; the two identity lines at the top stay visible.
  • Double-click in the CODE panel to jump the editor to the definition.
  • Globals, locals, function parameters, and struct members all resolve to their declaration/definition.

Syntax highlighting and colors

  • Keywords, user types, functions, strings, numbers, and macros/preprocessor lines are colored separately.
  • Global variables and enum constants are red; function locals/parameters are light blue.
  • Locals are approximated with function-level scope; locals take precedence when names collide.
  • Light theme is available via SI_THEME=light / --theme=light.
  • 256-color terminals show the full palette; 16-color terminals degrade automatically.

Code formatting

F6 or the Format Code... menu opens the chooser:

Format: [c] current file  [a] all files  [Esc] cancel
  • c / Enter: format the current buffer; undoable.
  • a: format all C/C++ files in the project, write them back to disk, and re-index.
  • Rules follow astyle --style=ansi: 4-space indent, the opening brace of a function on its own line, { on the same line for control statements, and trailing whitespace removed.
  • Preprocessor lines (#define, #if, and backslash continuations) are not reformatted.
  • Project-wide formatting refuses to run when any buffer has unsaved changes.

Compiling the project

Ctrl+F5 or Compile > Compile Project builds the current project:

  • If the project root contains Makefile, makefile, or GNUmakefile, make -C <root> is used. make must be present in PATH.
  • Otherwise the compiler is detected from PATH: cc → gcc → clang for C, and c++ → g++ → clang++ for C++. Each .c/.cc/.cpp/.cxx/.c++ file is compiled to build/obj/<relative-path>.o; the objects are linked to build/<project-name>. Mixed C/C++ projects use the matching compiler for each source file and link with the C++ driver. Include paths are added for every directory that contains project files.
  • Unsaved buffers are saved before compiling; if saving fails, compilation is cancelled.
  • If the required compiler (or make) is missing, the compile window reports the problem and no build command is started.
  • The centered compile window shows each command and the complete sanitized output. While a build is running, Esc / Ctrl+C cancels it (the compiler process group is terminated), and Up/Down/PgUp/PgDn or the wheel scrolls the output. After success, failure, or cancellation the window remains open with SUCCESS / FAILED / CANCELLED; press Enter or Esc to close it.
  • Compilation uses the saved files on disk. There are no per-project flag or cross-compiler settings yet; use a Makefile for custom toolchains.

Mouse and editing

  • Click any panel to focus it; click again to open a file/jump to a symbol.
  • Completion list: single-click selects, double-click accepts, the wheel scrolls; clicking outside the list closes it.
  • Right-click in the editor opens the Copy/Paste menu; right-click elsewhere opens the main menu.
  • Drag to select text, Ctrl+C to copy, Ctrl+V to paste; copying also writes to the OSC52 system clipboard.
  • All four splitters are draggable; hovering shows handles and the ratio.
  • For the terminal's own text selection, hold Shift while dragging (common behavior in GNOME Terminal and others).

Source layout

src/
  si.h         shared types, containers, limit constants
  util.c       strings/paths/directory traversal/UTF-8/atomic file writes
  text.c       editable buffer, line index, undo/redo, find, word boundaries
  syntax.c     C/C++ syntax highlighting via a line-based state machine
  index.c      project scanning, lexing, symbol/reference/text search, index cache
  compile.c    compiler/make detection, build plans, child process and output capture
  term.c       POSIX termios + ANSI; Windows console development backend; key decoding
  app.c        application state, focus, editing actions, search, navigation, main loop
  render.c     five-panel TUI, colors, status bar, help overlay
  main.c       command-line arguments and batch mode
tests/
  test_core.c  buffer/UTF-8/syntax/indexer/call relations
  test_keys.c  terminal key/mouse sequence decoding
  ui_smoke.c   UI driver tests without a terminal
  fixtures/    small C project
examples/demo  compilable example project
docs/          architecture notes and generator scripts

More implementation details are in docs/si-c-architecture.html.

Testing

Measured in the current Linux workspace:

make clean && make -j && make test

Results:

test_core: 364 checks, 0 failures
test_keys:  32 checks, 0 failures
ui_smoke:  374 checks, 0 failures

On macOS, test_keys also includes Option-key cases, so the check count differs from this machine. Tests cover buffer editing, UTF-8, syntax highlighting, project indexing, call relations, state history, compiler detection/build plans, terminal key/mouse decoding, five-panel rendering, the compile window, and the main UI actions.

Linux uses the same POSIX code path; it is recommended to run make clean && make -j && make test first on Linux. The Windows console backend is mainly for development and testing and is not a primary target platform.

Known limitations

  • The parser is heuristic: it does not expand macros and does not handle template instantiation, complete inheritance graphs, or overload resolution; class-member completion only merges base members that can be read directly from class X : public Base.
  • Reference search does not enter #define macro bodies; all branches of #if/#else are scanned.
  • "Find references", call relations, and project-wide text search read files on disk and do not include unsaved changes.
  • The file outline is not re-parsed after every keystroke; it updates after saving, reopening, or F5.
  • The recent project list records only project roots; selecting one opens main.c or the first file and does not restore the previously open file and cursor for that project.
  • The caller tree is limited to 8 levels and 200 nodes; there is no overload/virtual-function resolution and no complete inheritance graph (completion merges only direct base members).
  • CALL FLOW [ref] recognizes only direct function-value references inside function bodies; indirect relations such as assigning handler to auto h = handler; and registering h later are not followed.
  • Preprocessor conditionals are not expanded; the indexer scans as many #if / #else branches as possible and may list symbols from branches that are not actually compiled.
  • Local variables use a function-level symbol table; block-level {} scopes are approximated at function level. Inserting or deleting lines before a function temporarily shifts indexed line numbers; press F5 to rebuild when needed.
  • Completion does not resolve (*p).x, array subscripts, or dependent types after template specialization; Box<int> falls back to looking up members on Box. auto supports constructors, variable copies, address-of/reference, common literals, and the return types of ordinary/member functions, but performs no overload resolution and does not infer template-dependent return types or the element type of a range-for; if the type cannot be resolved, no list is shown.
  • For very long functions, the CODE preview shows only a window; scroll with the wheel / PgUp / PgDn.
  • Mouse drag selection and ordinary line editing are available, but there is no column selection, multiple cursors, split view, LSP, ctags import, or persistent symbol database.
  • Compilation uses the project Makefile when present; otherwise it runs a simple direct build with the detected compiler, -I flags for project directories, and the default compiler flags. There are no custom flags, build variants, or cross-compilation settings. A project without exactly one linkable program (for example a library or several main functions) will fail at the link step and show the compiler error.
  • Single files are limited to 4 MiB, projects to 20,000 files, and symbols to 200,000.
  • Primarily written for Linux; macOS is supported and verified; the Windows console backend is for development/testing only.

AI-generated notice

  • Code, tests, documentation: mainly generated by an AI coding assistant (OpenCode / DeepSeek).
  • Human role: defining requirements, choosing direction, reviewing results, and publishing the repository.
  • Nature of the project: an independent terminal implementation in the style of Source Insight; it is not an official Source Insight product and is not affiliated with the developer of Source Insight.
  • Risk notice: AI-generated code may contain errors, omissions, or security risks. Read, test, and review it yourself before using it in production.
  • License: MIT, see LICENSE.

License

MIT License. Copyright (c) 2026 si-c contributors.

About

A terminal Source Insight-style C/C++ editor and source browser in C11. AI-generated. 终端源码浏览器:五面板 TUI、项目索引、调用链,无第三方依赖。

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages