{"id":1510,"library":"icdiff","title":"Improved Colored Diff","description":"icdiff is a Python library and command-line utility for displaying diffs with improved colorization, making it easier to read changes side-by-side. It aims to be a more user-friendly alternative to traditional `diff` output. The current version is 2.0.10, and it maintains a fairly active release cadence with updates typically every few months.","status":"active","version":"2.0.10","language":"en","source_language":"en","source_url":"https://github.com/jeffkaufman/icdiff","tags":["diff","cli","utility","color","visualization"],"install":[{"cmd":"pip install icdiff","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"This is the main class for programmatic diff generation with console-style output.","symbol":"ConsoleDiff","correct":"from icdiff import ConsoleDiff"}],"quickstart":{"code":"from icdiff import ConsoleDiff\n\nold_text = [\n    \"line 1: hello world\",\n    \"line 2: foo bar\",\n    \"line 3: baz qux\"\n]\n\nnew_text = [\n    \"line 1: hello earth\",\n    \"line 2: foo baz\",\n    \"line 3: baz qux\",\n    \"line 4: new line\"\n]\n\ndiffer = ConsoleDiff(\n    cols=80,  # Specify number of columns for display\n    line_numbers=True, # Show line numbers\n    color=True # Enable color output\n)\n\ndiff_lines = differ.make_table(\n    old_text,\n    new_text,\n    fromfile='old_version.txt',\n    tofile='new_version.txt',\n    context=True # Show context lines\n)\n\nfor line in diff_lines:\n    print(line)","lang":"python","description":"This quickstart demonstrates how to use `ConsoleDiff` to generate a colored, side-by-side diff between two lists of strings. It configures the diff for a specific column width, includes line numbers, and sets custom file labels for the header."},"warnings":[{"fix":"Consider `difflib` for non-visual, programmatic diffing or when fine-grained control over diff algorithm is required without console-specific formatting.","message":"`icdiff` is primarily a command-line tool. While it offers a Python API, its main strength is interactive visualization. For purely programmatic diff parsing or generating diffs in non-console contexts, Python's built-in `difflib` might be more suitable or efficient, especially if raw diff data (not colored output) is needed.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always pass the actual content of the files as lists of strings (e.g., `file1.readlines()`) to `make_table()`. The `fromfile` and `tofile` arguments are just metadata for the output header.","message":"The `fromfile` and `tofile` arguments in `ConsoleDiff.make_table()` are purely for display labels in the diff header (e.g., `--- old_version.txt`). They do not instruct `icdiff` to read content from actual files. You must provide the file content as lists of strings.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When using `ConsoleDiff` programmatically and outputting to a non-TTY (like a file), instantiate it with `color=False` (e.g., `ConsoleDiff(color=False)`) to prevent ANSI escape codes from being included in the output.","message":"By default, `ConsoleDiff` tries to output ANSI color codes. If you redirect `icdiff`'s output to a file or pipe it to another command, you might end up with escape codes in the output. While `icdiff`'s CLI often detects non-TTY, the Python API might require explicit handling.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}