{"id":13763389,"url":"https://github.com/thatstoasty/mog","last_synced_at":"2026-02-22T16:44:22.144Z","repository":{"id":226062484,"uuid":"739967200","full_name":"thatstoasty/mog","owner":"thatstoasty","description":"Terminal based text styling, formatting, and layouts!","archived":false,"fork":false,"pushed_at":"2026-02-11T21:11:08.000Z","size":2457,"stargazers_count":55,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-02-12T03:52:17.178Z","etag":null,"topics":["css","mojo","terminal","tui"],"latest_commit_sha":null,"homepage":"","language":"Mojo","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thatstoasty.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-01-07T05:03:57.000Z","updated_at":"2026-02-11T21:11:11.000Z","dependencies_parsed_at":"2024-11-16T22:31:43.849Z","dependency_job_id":"b4a43392-34ec-437e-8600-c14810e62672","html_url":"https://github.com/thatstoasty/mog","commit_stats":null,"previous_names":["thatstoasty/mog"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thatstoasty/mog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thatstoasty%2Fmog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thatstoasty%2Fmog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thatstoasty%2Fmog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thatstoasty%2Fmog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thatstoasty","download_url":"https://codeload.github.com/thatstoasty/mog/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thatstoasty%2Fmog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29718669,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-22T15:10:41.462Z","status":"ssl_error","status_checked_at":"2026-02-22T15:10:04.636Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","mojo","terminal","tui"],"created_at":"2024-08-03T15:00:43.747Z","updated_at":"2026-02-22T16:44:22.121Z","avatar_url":"https://github.com/thatstoasty.png","language":"Mojo","funding_links":[],"categories":["🗂️ Libraries\u003ca id='libraries'\u003e\u003c/a\u003e"],"sub_categories":["CLI"],"readme":"# Mog\n\n![Mog example](https://github.com/thatstoasty/mog/blob/main/doc/images/mog.png)\n\nStyle definitions for nice terminal layouts.\n\n![Mojo Version](https://img.shields.io/badge/Mojo%F0%9F%94%A5-25.3-orange)\n![Build Status](https://github.com/thatstoasty/mog/actions/workflows/build.yml/badge.svg)\n![Test Status](https://github.com/thatstoasty/mog/actions/workflows/test.yml/badge.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Attributions\n\n* Ported from/Inspired by: \u003chttps://github.com/charmbracelet/lipgloss/tree/master\u003e\n  * If you're a Go developer, please check out their CLI tooling and libraries. They're amazing!\n\n## Installation\n\n1. First, you'll need to configure your `mojoproject.toml` file to include my Conda channel. Add `\"https://repo.prefix.dev/mojo-community\"` to the list of channels.\n2. Next, add `mog` to your project's dependencies by running `magic add mog`.\n3. Finally, run `magic install` to install in `mog` and its dependencies. You should see the `.mojopkg` files in `$CONDA_PREFIX/lib/mojo/`.\n\n![Mog example](https://github.com/thatstoasty/mog/blob/main/doc/images/layout.png)\n\nMog takes an expressive, declarative approach to terminal rendering.\nUsers familiar with CSS will feel at home with Mog.\n\n```mojo\nimport mog\n\nfn main():\n    var style = mog.Style() \\\n        .bold() \\\n        .foreground(mog.Color(0xFAFAFA)) \\\n        .background(mog.Color(0x7D56F4)) \\\n        .padding_top(2) \\\n        .padding_left(4) \\\n        .width(22)\n\n    print(style.render(\"Hello, kitty\"))\n```\n\n## Colors\n\nMog supports the following color profiles:\n\n### ANSI 16 colors (4-bit)\n\n```mojo\nimport mog\n\nmog.Color(5) # magenta\nmog.Color(9)  # red\nmog.Color(12) # light blue\n```\n\n### ANSI 256 Colors (8-bit)\n\n```mojo\nimport mog\n\nmog.Color(86)  # aqua\nmog.Color(201) # hot pink\nmog.Color(202) # orange\n```\n\n### True Color (16,777,216 colors; 24-bit)\n\n```mojo\nimport mog\n\nfn main():\n    var color = mog.Color(0x0000FF) # 100% blue\n    color = mog.Color(0x04B575) # green\n    color = mog.Color(0x3C3C3C) # dark gray\n```\n\n...as well as a 1-bit ASCII profile, which is black and white only.\n\nThe terminal's color profile is automatically detected and colors outside\nthe gamut of the current palette will be automatically coerced to their closest\navailable value.\n\nFor now, the library assumes a dark background. You can set this to light by modifying the style's profile field.\n\n### Adaptive Colors\n\nYou can also specify color options for light and dark backgrounds:\n\n```mojo\nimport mog\n\nfn main():\n    var color = mog.AdaptiveColor(light=236, dark=248)\n```\n\n### Complete Colors\n\n`CompleteColor` specifies exact values for `TRUE_COLOR`, `ANSI256`, and `ANSI` color\nprofiles.\n\n```mojo\nimport mog\n\nfn main():\n    var color = mog.CompleteColor(true_color=0x0000FF, ansi256=86, ansi=5)\n```\n\nAutomatic color degradation will not be performed in this case and it will be\nbased on the color specified.\n\n### Complete Adaptive Colors\n\nYou can use `CompleteColor` with `AdaptiveColor` to specify the exact values for\nlight and dark backgrounds without automatic color degradation.\n\n```mojo\nimport mog\n\nfn main():\n    var color = mog.CompleteAdaptiveColor(\n        light = mog.CompleteColor(true_color=0xd7ffae, ansi256=193, ansi=11),\n        dark = mog.CompleteColor(true_color=0xd75fee, ansi256=163, ansi=5),\n    )\n\n```\n\n## Inline Formatting\n\n`Mog` supports the usual ANSI text formatting options:\n\n```mojo\nimport mog\n\nfn main():\n    var style = mog.Style() \\\n        .bold() \\\n        .italic() \\\n        .faint() \\\n        .blink() \\\n        .crossout() \\\n        .underline() \\\n        .reverse()\n```\n\n## Block-Level Formatting\n\n`Mog` also supports rules for block-level formatting:\n\n```mojo\nimport mog\n\nfn main():\n    # Padding\n    var style = mog.Style() \\\n        .padding_top(2) \\\n        .padding_right(4) \\\n        .padding_bottom(2) \\\n        .padding_left(4)\n\n    # Margins\n    var style = mog.Style() \\\n        .margin_top(2) \\\n        .margin_right(4) \\\n        .margin_bottom(2) \\\n        .margin_left(4)\n```\n\nThere is also shorthand syntax for margins and padding, which follows the same\nformat as CSS:\n\n```mojo\nimport mog\n\nfn main():\n    # 2 cells on all sides\n    var style = mog.Style().padding(2)\n\n    # 2 cells on the top and bottom, 4 cells on the left and right\n    style = mog.Style().margin(2, 4)\n\n    # 1 cell on the top, 4 cells on the sides, 2 cells on the bottom\n    style = mog.Style().padding(1, 4, 2)\n\n    # Clockwise, starting from the top: 2 cells on the top, 4 on the right, 3 on\n    # the bottom, and 1 on the left\n    style = mog.Style().margin(2, 4, 3, 1)\n```\n\n## Aligning Text\n\nYou can align paragraphs of text to the left, right, or center.\n\n```mojo\nimport mog\nfrom mog import Position\n\nfn main():\n    var style = mog.Style() \\\n        .width(24) \\\n        .align(Position.LEFT) \\\n        .align(Position.RIGHT) \\\n        .align(Position.CENTER)\n```\n\n## Width and Height\n\nSetting a minimum width and height is simple and straightforward.\n\n```mojo\nimport mog\n\nfn main():\n    var style = mog.Style(value=\"What’s for lunch?\") \\\n        .width(24) \\\n        .height(32) \\\n        .foreground(mog.Color(63))\n```\n\n## Borders\n\nAdding borders is easy:\n\n```mojo\nimport mog\n\nfn main():\n    # Add a purple, rectangular border\n    var style = mog.Style() \\\n        .border(NORMAL_BORDER) \\\n        .border_foreground(mog.Color(63))\n\n    # Set a rounded, yellow-on-purple border to the top and left\n    var another_style = mog.Style() \\\n        .border(ROUNDED_BORDER) \\\n        .border_foreground(mog.Color(228)) \\\n        .border_background(mog.Color(63)) \\\n        .border_top(True) \\\n        .border_left(True)\n\n    # Make your own border\n    var my_border = Border(\n        top             = \"._.:*:\",\n        bottom          = \"._.:*:\",\n        left            = \"|*\",\n        right           = \"|*\",\n        top_left        = \"*\",\n        top_right       = \"*\",\n        bottom_left     = \"*\",\n        bottom_right    = \"*\",\n    )\n```\n\nThere are also shorthand functions for defining borders, which follow a similar\npattern to the margin and padding shorthand functions.\n\n```mojo\nimport mog\n\nfn main():\n    # Add a thick border to the top and bottom\n    var style = mog.Style().border(THICK_BORDER, True, False)\n\n    # Add a double border to the top and left sides. Rules are set clockwise\n    # from top.\n    style = mog.Style().border(DOUBLE_BORDER, True, False, False, True)\n```\n\n## Unsetting Rules\n\nAll rules can be unset:\n\n```mojo\nimport mog\n\nfn main():\n    var style = mog.Style() \\\n        .bold() \\\n        .unset_bold() \\\n        .background(mog.Color(227)) \\\n        .unset_background()\n```\n\nWhen a rule is unset, it won't be inherited or copied.\n\n## Setting and Unsetting Rules\n\nWhen a rule is set, under the hood the rule is marked as set, and then the value of the rule is stored.\nWhen the rule is unset, the rule is marked as unset, but the value is **not** removed.\n\nFor boolean rules, such as `bold`, the rule must be set and the value must be `True` for the rule to be applied.\n\nThis leads to the following behavior:\n\n```mojo\nimport mog\n\nfn main():\n    # Bold is set, and the value is set to True. Text output is bold.\n    var style = mog.Style().bold()\n\n    # Bold is set, and the value is set to False. Text output is not bold.\n    var style = mog.Style().bold(False)\n\n    # Bold is not set, and the value is set to True. Text output is not bold.\n    var style = mog.Style().bold().unset_bold()\n\n    # Bold is not set, and the value is set to False. Text output is not bold.\n    var style = mog.Style().bold(False).unset_bold()\n```\n\n## Enforcing Rules\n\nSometimes, such as when developing a component, you want to make sure style\ndefinitions respect their intended purpose in the UI. This is where `inline`\nand `max_width`, and `max_height` come in:\n\n```mojo\nimport mog\n\nfn main():\n    var style = mog.Style()\n    # Force rendering onto a single line, ignoring margins, padding, and borders.\n    print(style.inline().render(\"yadda yadda\"))\n\n    # Also limit rendering to five cells\n    print(style.inline().max_width(5).render(\"yadda yadda\"))\n\n    # Limit rendering to a 5x5 cell block\n    print(style.max_width(5).max_height(5).render(\"yadda yadda\"))\n```\n\n* `inline` will force the text to render on a single line, ignoring margins, padding, and borders.\n* `max_width` will limit the width of the rendered text, by truncating lines that are too long.\n  * If you want to all lines to be a certain length, use `width` instead.\n  * Lines will only be padded to the width of the widest line, and not up to `max_width`.\n* `max_height` will limit the height of the rendered text, by truncating lines from the bottom of the block.\n  * If you want to ensure the text is a certain height, use `height` instead.\n\n## Tabs\n\nThe tab character (`\\t`) is rendered differently in different terminals (often\nas 8 spaces, sometimes 4). Because of this inconsistency, `Mog` converts\ntabs to 4 spaces at render time. This behavior can be changed on a per style\nbasis, however:\n\n```mojo\nimport mog\n\nfn main():\n    var style = mog.Style() # tabs will render as 4 spaces, the default\n    style = style.tab_width(2) # render tabs as 2 spaces\n    style = style.tab_width(0) # remove tabs entirely\n    style = style.tab_width(mog.NO_TAB_CONVERSION) # leave tabs intact\n```\n\n## Rendering\n\nYou can render text with a style using the `render` method:\n\n```mojo\nimport mog\n\nfn main():\n    var style = mog.Style(value=\"Hello,\").bold()\n    print(style.render(\"Mojo.\")) # Hello, Mojo.\n    print(style.render(\"Python.\")) # Hello, Python.\n    print(style.render(\"my\", \"friends.\")) # Hello, my friends.\n```\n\n### Custom Renderers\n\nCustom renderers allow you to render to a specific outputs. This is\nparticularly important when you want to render to different outputs and\ncorrectly detect the color profile and dark background status for each, such as\nin a server-client situation.\n\n```mojo\nimport mog\n\nfn main():\n    # Create a renderer for the client.\n    var custom_renderer = mog.Renderer(mog.ANSI)\n\n    # Create a new style using the custom renderer.\n    var style = mog.Style().background(mog.AdaptiveColor(light=63, dark=228))\n    var custom_style = style.renderer(custom_renderer)\n\n    # Render some output using the styles.\n    # `style` uses the default renderer which will detect the color profile and dark background state.\n    # `custom_style` will use the custom renderer, which has manually set the color profile to `ANSI` (0-15 color support).\n    print(style.render(\"Automatic renderer output!\"))\n    print(custom_style.render(\"Manual renderer output!\"))\n\n```\n\n## Utilities\n\n`Mog` also includes utilities to assemble your layouts.\n\n### Joining Paragraphs\n\nCompose your text blocks easily using `join_horizontal` and `join_vertical`.\n\n```mojo\nimport mog\n\nfn main():\n    var paragraph_a = \"Hello, world!\"\n    var paragraph_b = \"How are you?\"\n    var paragraph_c = \"I'm doing well.\\nThank you.\"\n\n    # Horizontally join three paragraphs along their bottom edges\n    mog.join_horizontal(mog.bottom, paragraph_a, paragraph_b, paragraph_c)\n\n    # Vertically join two paragraphs along their center axes\n    mog.join_vertical(mog.center, paragraph_a, paragraph_b)\n\n    # Horizontally join three paragraphs, with the shorter ones aligning 20%\n    # from the top of the tallest\n    mog.join_horizontal(0.2, paragraph_a, paragraph_b, paragraph_c)\n```\n\n### Measuring Width and Height\n\nWhen building layouts, you'll want to know the the width and/or height of text blocks.\n`Mog` provides functions to get the dimensions of the text block, accounting for ANSI sequences\nand unicode codepoints being 0-2 cells wide.\n\n```mojo\nimport mog\n\nfn main():\n    # render a block of text.\n    var style = mog.Style() \\\n        .width(40) \\\n        .padding(2)\n    var block = style.render(some_long_string)\n\n    # Get the actual, physical dimensions of the text block.\n    var width = mog.get_width(block)\n    var height = mog.get_height(block)\n\n    # Here's a shorthand function.\n    var dimensions = mog.get_dimensions(block)\n```\n\n### Placing Text in Whitespace\n\nSometimes you’ll simply want to place a block of text in whitespace.\n\n```mojo\nfrom mog import place, place_horizontal, place_vertical\n\nfn main():\n    # Center a paragraph horizontally in a space 80 cells wide. The height of\n    # the block returned will be as tall as the input paragraph.\n    block = place_horizontal(80, mog.center, fancy_styled_paragraph)\n\n    # Place a paragraph at the bottom of a space 30 cells tall. The width of\n    # the text block returned will be as wide as the input paragraph.\n    block = place_vertical(30, mog.bottom, fancy_styled_paragraph)\n\n    # Place a paragraph in the bottom right corner of a 30x80 cell space.\n    block = place(30, 80, mog.right, mog.bottom, fancy_styled_paragraph)\n```\n\nThe `place` functions use a default `Renderer`, which attempts to detect the color profile supported and assumes a dark background terminal. If you'd like to explicitly set the color profile and background, you can create your own `Renderer`, use it's `place` methods.\n\n```mojo\nimport mog\n\nfn main():\n    # Set the color profile to ANSI (0-15 colors) and the background to light manually.\n    var renderer = mog.Renderer(mog.ANSI, dark_background=False)\n    var block = renderer.place_horizontal(80, mog.center, fancy_styled_paragraph)\n    block = renderer.place_vertical(30, mog.bottom, fancy_styled_paragraph)\n    block = renderer.place(30, 80, mog.right, mog.bottom, fancy_styled_paragraph)\n```\n\n### Rendering Tables\n\n`Mog` also has a module for rendering tables.\n\nDefine some rows of data.\n\n```mojo\nimport mog.table\n\nfn main():\n    var rows = List[List[String]](\n        List[String](\"Chinese\", \"您好\", \"你好\"),\n        List[String](\"Japanese\", \"こんにちは\", \"やあ\"),\n        List[String](\"Arabic\", \"أهلين\", \"أهلا\"),\n        List[String](\"Russian\", \"Здравствуйте\", \"Привет\"),\n        List[String](\"Spanish\", \"Hola\", \"¿Qué tal?\"),\n    )\n    ...\n```\n\nUse the table package to style and render the table.\n\n```mojo\nimport mog\n\nfn main():\n    ...\n    var t = mog.Table.new().\n        .border(NORMAL_BORDER) \\\n        .border_style(mog.Style().foreground(mog.Color(99))) \\\n        .headers(\"LANGUAGE\", \"FORMAL\", \"INFORMAL\") \\\n        .rows(rows)\n\n    # You can also add tables row-by-row\n    t.row(\"English\", \"You look absolutely fabulous.\", \"How's it going?\")\n```\n\nPrint the table.\n\n```mojo\nprint(t)\n```\n\nHere's an example table rendering!\n\n![Mog example](https://github.com/thatstoasty/mog/blob/main/doc/tapes/pokemon.gif)\n\n---\n\n## TODO\n\n* Add style ranges.\n\n### Check out these other libraries in the Mojo Community\n\n* `A Mojo HTTP framework with wings` - [@saviorand/lightbug_http](https://github.com/saviorand/lightbug_http)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthatstoasty%2Fmog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthatstoasty%2Fmog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthatstoasty%2Fmog/lists"}