Skip to content

Commit

Permalink
mojo 24.4 updates, but compilation is really slow
Browse files Browse the repository at this point in the history
  • Loading branch information
thatstoasty committed Jun 8, 2024
1 parent c9266e5 commit 10806ac
Show file tree
Hide file tree
Showing 52 changed files with 1,327 additions and 1,246 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Mog

![Mojo 24.3](https://img.shields.io/badge/Mojo%F0%9F%94%A5-24.3-purple)
![Mojo 24.4](https://img.shields.io/badge/Mojo%F0%9F%94%A5-24.4-purple)

Style definitions for nice terminal layouts. Built with TUIs in mind.
Ported from/Inspired by: <https://github.com/charmbracelet/lipgloss/tree/master>
Expand Down
7 changes: 3 additions & 4 deletions examples/readme/layout.mojo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from math import max
from external.gojo.strings import StringBuilder
from external.weave.ansi import printable_rune_width
from mog.join import join_vertical, join_horizontal
Expand All @@ -23,7 +22,7 @@ alias special = mog.AdaptiveColor(light="#43BF6D", dark="#73F59F")


fn build_tabs() raises -> String:
var active_tab_border = Border(
alias active_tab_border = Border(
top="",
bottom=" ",
left="",
Expand All @@ -34,7 +33,7 @@ fn build_tabs() raises -> String:
bottom_right="",
)

var tab_border = Border(
alias tab_border = Border(
top="",
bottom="",
left="",
Expand Down Expand Up @@ -248,4 +247,4 @@ fn main() raises:
_ = builder.write_string(build_status_bar())

# Render the final document with doc_style
print(doc_style.render(str(builder)))
print(doc_style.render(builder.render()))
1 change: 0 additions & 1 deletion external/gojo/builtins/__init__.mojo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .bytes import Byte, index_byte, has_suffix, has_prefix, to_string
from .list import equals
from .attributes import cap, copy
from .errors import exit, panic

Expand Down
53 changes: 53 additions & 0 deletions external/gojo/builtins/attributes.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,59 @@ fn copy[T: CollectionElement](inout target: List[T], source: List[T], start: Int
return count


fn copy(
inout target: List[UInt8],
source: DTypePointer[DType.uint8],
source_start: Int,
source_end: Int,
target_start: Int = 0,
) -> Int:
"""Copies the contents of source into target at the same index. Returns the number of bytes copied.
Added a start parameter to specify the index to start copying into.
Args:
target: The buffer to copy into.
source: The buffer to copy from.
source_start: The index to start copying from.
source_end: The index to stop copying at.
target_start: The index to start copying into.
Returns:
The number of bytes copied.
"""
var count = 0

for i in range(source_start, source_end):
if i + target_start > len(target):
target[i + target_start] = source[i]
else:
target.append(source[i])
count += 1

return count


# fn copy[T: CollectionElement](inout target: Span[T], source: Span[T], start: Int = 0) -> Int:
# """Copies the contents of source into target at the same index. Returns the number of bytes copied.
# Added a start parameter to specify the index to start copying into.

# Args:
# target: The buffer to copy into.
# source: The buffer to copy from.
# start: The index to start copying into.

# Returns:
# The number of bytes copied.
# """
# var count = 0

# for i in range(len(source)):
# target[i + start] = source[i]
# count += 1

# return count


fn cap[T: CollectionElement](iterable: List[T]) -> Int:
"""Returns the capacity of the List.
Expand Down
29 changes: 26 additions & 3 deletions external/gojo/builtins/bytes.mojo
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from .list import equals
alias Byte = UInt8


alias Byte = Int8
fn equals(left: List[UInt8], right: List[UInt8]) -> Bool:
if len(left) != len(right):
return False
for i in range(len(left)):
if left[i] != right[i]:
return False
return True


fn has_prefix(bytes: List[Byte], prefix: List[Byte]) -> Bool:
Expand Down Expand Up @@ -44,14 +50,31 @@ fn index_byte(bytes: List[Byte], delim: Byte) -> Int:
Returns:
The index of the first occurrence of the byte delim.
"""
var i = 0
for i in range(len(bytes)):
if bytes[i] == delim:
return i

return -1


fn index_byte(bytes: DTypePointer[DType.uint8], size: Int, delim: Byte) -> Int:
"""Return the index of the first occurrence of the byte delim.
Args:
bytes: The DTypePointer[DType.int8] struct to search.
size: The size of the bytes pointer.
delim: The byte to search for.
Returns:
The index of the first occurrence of the byte delim.
"""
for i in range(size):
if UInt8(bytes[i]) == delim:
return i

return -1


fn to_string(bytes: List[Byte]) -> String:
"""Makes a deepcopy of the List[Byte] supplied and converts it to a string. If it's not null terminated, it will append a null byte.
Expand Down
133 changes: 0 additions & 133 deletions external/gojo/builtins/list.mojo

This file was deleted.

Loading

0 comments on commit 10806ac

Please sign in to comment.