sc-im (Spreadsheet Calculator Improvised)

repository·main·Indexed 26 days ago

https://github.com/andmarti1424/sc-im

An ncurses-based, Vim-like spreadsheet calculator providing a terminal-based interface for spreadsheet manipulation. It supports Vim movements, Lua scripting, and various file formats including CSV, XLSX, and ODS. The tool includes a non-interactive mode for pipeline processing via the --nocurses flag and is configurable through a scimrc file.

Tokens
1.4K
Snippets
1
Records
11
Agent score
91%

What's inside sc-im

  1. Install sc-im from source

    main

    To build sc-im manually, ensure you have the required dependencies installed and follow these steps:

    1. Edit the Makefile: Customize src/Makefile based on your system requirements.
    2. Compile: Run make within the src directory.
    3. Install (Optional): Install the binary to your system using a privileged user.

    Required Dependencies

    • ncurses (preferably with wide character support)
    • bison or yacc
    • gcc
    • make
    • pkg-config and which

    Optional Dependencies

    • tmux / xclip / pbpaste: For clipboard support
    • gnuplot: For plotting
    • libxlsxreader: For XLS support
    • xlsxwriter: For XLSX export support
    • libxml-2.0 and libzip: For XLSX/ODS import support
    • lua: For Lua scripting
  2. Quick start guide for sc-im

    main

    sc-im uses Vim-like keybindings for navigation and spreadsheet manipulation. Use the following commands to interact with the spreadsheet:

    Cell Editing

    • =: Insert a numeric value
    • \: Insert a text value
    • e: Edit a numeric value
    • E: Edit a string value
    • x: Delete current cell content
    • h, j, k, l: Move left, down, up, and right respectively
    • goab12: Jump to cell AB12 (replace with target cell)
    • v: Select a range using cursor and hjkl keys

    Spreadsheet Operations

    • ir: Insert row
    • ic: Insert column
    • dr: Delete row
    • dc: Delete column
    • yy: Copy (yank) current cell
    • p: Paste previously yanked cell or range
    • u: Undo last change
    • C-r: Redo last change

    File and App Management

    • :q: Quit the application
    • :h: See help
    • :w filename.sc: Save current spreadsheet in .sc format
  3. Configure sc-im using scimrc

    main

    Configuration is handled via the scimrc file. This file must be placed in the ~/.config/sc-im directory.

    Example ~/.config/sc-im/scimrc content:

    set autocalc
    set numeric
    set numeric_decimal=0
    set overlap
    set xlsx_readformulas

    For a full list of configuration variables, refer to the internal help file within the application.

  4. Use sc-im in non-interactive mode (Pipeline)

    main

    You can use sc-im in a pipeline by using the --nocurses flag. In this mode, sc-im reads commands from stdin and can be used for automated processing.

    When --nocurses is active, the application will read lines from stdin and send them to the internal interpreter. After processing the input, you can use the --output flag to capture the results.

  5. Core application lifecycle functions in sc-im

    main

    The sc-im core provides functions to manage the application lifecycle, including initialization, structure management, and clean exit.

    • create_structures(): Initializes the internal data structures required for the spreadsheet engine.
    • delete_structures(): Cleans up and deallocates the internal data structures.
    • exit_app(int status): Terminates the application with the specified exit status.
    • main(int argc, char ** argv): The primary entry point for the application.
  6. Handle system signals in sc-im

    main

    The application manages several system signals to ensure stability and proper behavior:

    • signals(): Sets up the signal handlers.
    • sig_int(int signum): Handler for the interrupt signal (SIGINT).
    • sig_nopipe(int signum): Handler for pipe-related signals.
    • sig_winchg(int signum): Handler for window change signals (SIGWINCH).
  7. Manage sc-im command line arguments and input

    main

    Functions for handling application startup via command line arguments or standard input:

    • read_argv(int argc, char ** argv): Parses command line arguments.
    • read_stdin(): Reads input from standard input.
    • handle_argv_exports(): Handles exported arguments/commands.
    • show_version_and_quit(): Displays the current version of sc-im and exits.
    • show_usage_and_quit(): Displays the command usage information and exits.
  8. Reference global state variables in sc-im

    main

    The following global variables are exported for access to the application's runtime state:

    • fdoutput: A FILE * representing the output file descriptor (typically stdout or a file).
    • curmode: An unsigned int representing the current application mode.
    • lastmode: An unsigned int representing the previous application mode.
    • startup_tv: A struct timeval recording the application startup time.
    • current_tv: A struct timeval recording the current runtime time.
  9. Run sc-im with command line arguments

    main

    The sc-im executable accepts command line arguments to configure its behavior or load specific files.

    • Files: Any argument that does not start with -- is treated as a filename to be loaded. If multiple files are provided, the last one is used.
    • Parameters: Arguments starting with -- are parsed as configuration parameters and stored in the internal configuration dictionary.
    • Special Flags:
      • --help: Displays usage information and exits.
      • --version: Displays the version information and exits.
      • --nocurses: Disables the ncurses TUI, allowing sc-im to run in a non-interactive mode (e.g., for piping input/output).
      • --output <file>: Redirects the application output to the specified file instead of stdout.
      • --export_csv, --export_tab, --export_mkd, --export_txt, --export: Triggers specific export formats upon loading the file.