Skip to content

Commit

Permalink
Update to 24.5 (#18)
Browse files Browse the repository at this point in the history
* WIP for nightly, unicode characters kinda broke a good chunk of the examples

* unicode working in nightly again :)

* fix up benchmarks

* fix up benchmarks

* add new workflows

* add new workflows

* add new workflows

* fix build

* ver up

* prepare 24.5

* prepare 24.5

* test on mac
  • Loading branch information
thatstoasty authored Sep 13, 2024
1 parent 51d3365 commit a8a60c0
Show file tree
Hide file tree
Showing 112 changed files with 2,220 additions and 10,551 deletions.
76 changes: 0 additions & 76 deletions .devcontainer/Dockerfile

This file was deleted.

18 changes: 0 additions & 18 deletions .devcontainer/devcontainer.json

This file was deleted.

51 changes: 51 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build all packages

on:
push:
branches:
- main

# on: ["push"]

jobs:
build:
strategy:
matrix:
include:
- { target: linux-64, os: ubuntu-latest }
- { target: osx-arm64, os: macos-14 }
fail-fast: false

runs-on: ${{ matrix.os }}
timeout-minutes: 5

defaults:
run:
shell: bash

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Install magic
run: |
curl -ssL https://magic.modular.com | bash
- name: Build package for target platform
env:
TARGET_PLATFORM: ${{ matrix.target }}
PREFIX_API_KEY: ${{ secrets.PREFIX_API_KEY }}
CONDA_BLD_PATH: ${{ runner.workspace }}/.rattler

run: |
source $HOME/.bash_profile
# Temporary method to fetch the rattler binary.
RATTLER_BINARY="rattler-build-aarch64-apple-darwin"
if [[ $TARGET_PLATFORM == "linux-64" ]]; then RATTLER_BINARY="rattler-build-x86_64-unknown-linux-musl"; fi
curl -SL --progress-bar https://github.com/prefix-dev/rattler-build/releases/latest/download/${RATTLER_BINARY} -o rattler-build
chmod +x rattler-build
# Build and push
magic run build --target-platform=$TARGET_PLATFORM
magic run publish
45 changes: 29 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,38 @@ name: Run Tests

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
pull-requests: read

jobs:
test:
runs-on: ubuntu-latest
environment: basic
name: with ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-14"]

runs-on: ${{ matrix.os }}
timeout-minutes: 5

defaults:
run:
shell: bash

steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Install dependencies
- name: Checkout repo
uses: actions/checkout@v4

- name: Install magic
run: |
curl https://get.modular.com | MODULAR_AUTH=${{ secrets.MODULAR_AUTH }} sh -
modular auth ${{ secrets.MODULAR_AUTH }}
modular install mojo
pip install pytest
pip install git+https://github.com/guidorice/mojo-pytest.git
- name: Unit Tests
curl -ssL https://magic.modular.com | bash
- name: Run tests
run: |
export MODULAR_HOME="/home/runner/.modular"
export PATH="/home/runner/.modular/pkg/packages.modular.com_mojo/bin:$PATH"
pytest tests/unit
pytest tests/integration
bash run_examples.sh
source $HOME/.bash_profile
magic run tests
magic run benchmarks
magic run examples
18 changes: 17 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,20 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/

# pixi environments
.pixi
*.egg-info

# magic environments
.magic

# Rattler
output

# VSCode
.vscode/

# Mojo
*.mojopkg
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
hooks:
- id: mojo-format
name: mojo-format
entry: mojo format -l 120
entry: magic run mojo format -l 120
language: system
files: '\.(mojo|🔥)$'
stages: [commit]
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ If you're a Go developer, please check out their CLI tooling and libraries. They

For bugs and todos, see the bottom of the readme. At the moment, characters with a printable length greater than 1 ARE NOT supported.

You should be able to build the package by running `mojo package mog -I external`. For the easiest usage method, I recommend just copying the entire external folder into your repository, then copy the `mog` folder into the external folder as well.
## Installation

> NOTE: It seems like `.mojopkg` files don't like being part of another package, eg. sticking all of your external deps in an `external` or `vendor` package. The only way I've gotten mojopkg files to work is to be in the same directory as the file being executed, and that directory cannot be a mojo package.
1. 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.
2. Next, add `mog` to your project's dependencies by running `magic add mog`.
3. Finally, run `magic install` to install in `mog` and its dependencies. You should see the `.mojopkg` files in `$CONDA_PREFIX/lib/mojo/`.

![Mog example](https://github.com/thatstoasty/mog/blob/main/demos/tapes/layout.gif)
![Mog example](https://github.com/thatstoasty/mog/blob/main/doc/tapes/layout.gif)

Mog takes an expressive, declarative approach to terminal rendering.
Users familiar with CSS will feel at home with Mog.
Expand Down Expand Up @@ -408,7 +410,7 @@ print(t)

Here's an example table rendering!

![Mog example](https://github.com/thatstoasty/mog/blob/main/demos/tapes/pokemon.gif)
![Mog example](https://github.com/thatstoasty/mog/blob/main/doc/tapes/pokemon.gif)

---

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ fn basic_styling():
)

var output = style.render("Hello, kitty")
keep(output)
_ = output


var file_style = (
mog.Style()
alias file_style = (
mog.Style(color_profile=mog.TRUE_COLOR)
.bold(True)
.foreground(mog.Color(0xFAFAFA))
.background(mog.Color(0x7D56F4))
Expand All @@ -30,7 +30,7 @@ var file_style = (

fn basic_comptime_styling():
var output = file_style.render("Hello, kitty")
keep(output)
_ = output


fn basic_styling_big_file():
Expand All @@ -42,6 +42,6 @@ fn basic_styling_big_file():
100
)
var output = style.render(content)
keep(output)
_ = output
except e:
print(e)
8 changes: 4 additions & 4 deletions benchmarks/layout.mojo → benchmarks/functions/layout.mojo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from benchmark.compiler import keep
from external.gojo.strings import StringBuilder
from external.weave.ansi import printable_rune_width
from gojo.strings import StringBuilder
from weave.ansi import printable_rune_width
import mog
from mog.join import join_vertical, join_horizontal
from mog.border import HIDDEN_BORDER, NORMAL_BORDER, ROUNDED_BORDER, Border
Expand Down Expand Up @@ -240,5 +240,5 @@ fn render_layout():

# Status bar
_ = builder.write_string(build_status_bar())
var output = doc_style.render(builder.render())
keep(output)
var output = doc_style.render(str(builder))
_ = output
10 changes: 5 additions & 5 deletions benchmarks/run.mojo
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import benchmark
from benchmarks.layout import render_layout
from benchmarks.basic_styling import (
from functions.layout import render_layout
from functions.basic_styling import (
basic_styling,
basic_styling_big_file,
basic_comptime_styling,
)
import mog


var style = mog.Style().alignment(mog.center, mog.center).padding(0, 1)
var header_style = style.foreground(mog.Color(0x39E506))
alias style = mog.Style(color_profile=mog.TRUE_COLOR).alignment(mog.center, mog.center).padding(0, 1)
alias header_style = style.foreground(mog.Color(0x39E506))


fn table_styling(row: Int, col: Int) -> mog.Style:
Expand Down Expand Up @@ -62,7 +62,7 @@ fn main():
)

# var bs_big_report = benchmark.run[basic_styling_big_file](max_iters=10)
# results.row(
# results = results.row(
# "Large file test",
# str(bs_big_report.mean(benchmark.Unit.ms)),
# str(bs_big_report.duration(benchmark.Unit.ms)),
Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
Empty file removed examples/__init__.mojo
Empty file.
File renamed without changes.
File renamed without changes.
16 changes: 5 additions & 11 deletions examples/readme/layout.mojo → examples/layout.mojo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from external.gojo.strings import StringBuilder
from external.weave.ansi import printable_rune_width
from gojo.strings import StringBuilder
from weave.ansi import printable_rune_width
from mog.join import join_vertical, join_horizontal
from mog.border import HIDDEN_BORDER, NORMAL_BORDER, ROUNDED_BORDER, Border
from mog.style import Style
Expand Down Expand Up @@ -94,7 +94,6 @@ fn build_dialog_box() -> String:
var buttons = join_horizontal(position.top, ok_button, cancel_button)
var ui = join_vertical(position.center, question, buttons)

# TODO: Cannot handle unicode characters with a length greater than 1. For example: east asian characters like Kanji.
return place(
width,
9,
Expand All @@ -116,9 +115,7 @@ fn build_lists() -> String:
).margin_right(2)

var list_item = mog.Style().padding_left(2)

var check_mark = mog.Style().foreground(special).padding_right(1).render("")

var list_done = mog.Style().crossout().foreground(mog.AdaptiveColor(light=0x969B86, dark=0x696969))

var lists = join_horizontal(
Expand Down Expand Up @@ -166,9 +163,9 @@ fn build_history() -> String:
position.left
).foreground(mog.Color(0xFFFDF5)).background(highlight)

alias history_a = "The Romans learned from the Greeks that quinces slowly cooked with honey would set when cool. The Apicius gives a recipe for preserving whole quinces, stems and leaves attached, in a bath of honey diluted with defrutum: Roman marmalade. Preserves of quince and lemon appear (along with rose, apple, plum and pear) in the Book of ceremonies of the Byzantine Emperor Constantine VII Porphyrogennetos."
alias history_a = "The Romans learned from the Greeks that quinces slowly cooked with honey would 'set' when cool. The Apicius gives a recipe for preserving whole quinces, stems and leaves attached, in a bath of honey diluted with defrutum: Roman marmalade. Preserves of quince and lemon appear (along with rose, apple, plum and pear) in the Book of ceremonies of the Byzantine Emperor Constantine VII Porphyrogennetos."
alias history_b = "Medieval quince preserves, which went by the French name cotignac, produced in a clear version and a fruit pulp version, began to lose their medieval seasoning of spices in the 16th century. In the 17th century, La Varenne provided recipes for both thick and clear cotignac."
alias history_c = "In 1524, Henry VIII, King of England, received a box of marmalade from Mr. Hull of Exeter. This was probably marmelada, a solid quince paste from Portugal, still made and sold in southern Europe today. It became a favourite treat of Anne Boleyn and her ladies in waiting."
alias history_c = "In 1524, Henry VIII, King of England, received a 'box of marmalade' from Mr. Hull of Exeter. This was probably marmelada, a solid quince paste from Portugal, still made and sold in southern Europe today. It became a favourite treat of Anne Boleyn and her ladies in waiting."

return join_horizontal(
position.top,
Expand All @@ -180,14 +177,11 @@ fn build_history() -> String:

fn build_status_bar() -> String:
var status_nugget_style = mog.Style().foreground(mog.Color(0xFFFDF5)).padding(0, 1)

var status_bar_style = mog.Style().foreground(mog.Color(0xC1C6B2)).background(mog.Color(0x353533))

var status_style = mog.Style().foreground(mog.Color(0xFFFDF5)).background(mog.Color(0xFF5F87)).padding(0, 1)
# .margin_right(1)

var encoding_style = status_nugget_style.background(mog.Color(0xA550DF)).horizontal_alignment(position.right)

var status_text_style = status_bar_style.padding_left(1)
var fish_cake_style = status_nugget_style.background(mog.Color(0x6124DF))

Expand Down Expand Up @@ -238,4 +232,4 @@ fn main():
_ = builder.write_string(build_status_bar())

# Render the final document with doc_style
print(doc_style.render(builder.render()))
print(doc_style.render(str(builder)))
Loading

0 comments on commit a8a60c0

Please sign in to comment.