Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rm copy #13

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2023, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# The Dockerfile is provided as reference. Please review the redistribution
# terms of the Mojo license in Section 1 (https://www.modular.com/legal/mojo)
# prior to distributing pre-built container images.
# ===----------------------------------------------------------------------=== #

# Example command line:
# Use no-cache to force docker to rebuild layers of the image by downloading the SDK from the repos
# ./build-image.sh --auth-key <your-modular-auth-key>
#

FROM ubuntu:22.04

ARG DEFAULT_TZ=America/Los_Angeles
ENV DEFAULT_TZ=$DEFAULT_TZ

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive TZ=$DEFAULT_TZ apt-get install -y \
tzdata \
vim \
nano \
sudo \
curl \
wget \
python3-pip \
git && \
rm -rf /var/lib/apt/lists/*


# Download the latest version of minicoda py3.8 for linux x86/x64.
# RUN curl -fsSL https://repo.anaconda.com/miniconda/$( wget -O - https://repo.anaconda.com/miniconda/ 2>/dev/null | grep -o 'Miniconda3-py38_[^"]*-Linux-x86_64.sh' | head -n 1) > /tmp/miniconda.sh \
# && chmod +x /tmp/miniconda.sh \
# && /tmp/miniconda.sh -b -p /opt/conda

# RUN mkdir -p ~/miniconda3 \
# && wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh \
# && bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3 \
# && rm -rf ~/miniconda3/miniconda.sh

# ENV PATH=~/miniconda3/bin/conda:$PATH
# RUN conda init

RUN pip install \
pytest \
git+https://github.com/guidorice/mojo-pytest.git

# RUN pip install \
# jupyterlab \
# ipykernel \
# matplotlib \
# ipywidgets

RUN curl https://get.modular.com | sh -
# RUN modular auth examples && modular install nightly/mojo
RUN modular auth examples && modular install mojo

ARG MODULAR_HOME="/root/.modular"
ENV MODULAR_HOME=$MODULAR_HOME
# ENV PATH="$PATH:$MODULAR_HOME/pkg/packages.modular.com_nightly_mojo/bin"
ENV PATH="$PATH:$MODULAR_HOME/pkg/packages.modular.com_mojo/bin"

# Change permissions to allow for Apptainer/Singularity containers
RUN chmod -R a+rwX /root

# CMD ["jupyter", "lab", "--ip='*'", "--NotebookApp.token=''", "--NotebookApp.password=''","--allow-root"]
18 changes: 18 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Mojo",
"build": {
"dockerfile": "Dockerfile"
},
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {},
"extensions": [
"modular-mojotools.vscode-mojo",
// "ms-toolsai.jupyter"
// "modular-mojotools.vscode-mojo-nightly"
]
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Just use `copy()`:
```mojo
var style = mog.new_style().foreground(mog.Color("219"))

var wild_style = style.copy().blink(True)
var wild_style = style.blink(True)
```

`copy()` performs a copy on the underlying data structure ensuring that you get
Expand Down
30 changes: 12 additions & 18 deletions benchmarks/layout.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ fn build_tabs() -> String:

var tab_style = mog.new_style().border(tab_border).border_foreground(highlight).padding(0, 1)

var active_tab = tab_style.copy().border(active_tab_border, True)
var active_tab = tab_style.border(active_tab_border, True)

var tab_gap = tab_style.copy().border_top(False).border_left(False).border_right(False)
var tab_gap = tab_style.border_top(False).border_left(False).border_right(False)

var row = join_horizontal(
position.top,
Expand Down Expand Up @@ -86,7 +86,7 @@ fn build_dialog_box() -> String:
0, 3
).margin_top(1)

var active_button_style = button_style.copy().foreground(mog.Color("#FFF7DB")).background(
var active_button_style = button_style.foreground(mog.Color("#FFF7DB")).background(
mog.Color("#F25D94")
).margin_right(2).underline()

Expand Down Expand Up @@ -140,9 +140,7 @@ fn build_lists() -> String:
list_item.render("Pomelo"),
),
),
list_style.copy()
.width(column_width)
.render(
list_style.width(column_width).render(
join_vertical(
position.left,
list_header.render("Actual Lip Gloss Vendors"),
Expand All @@ -153,9 +151,7 @@ fn build_lists() -> String:
check_mark + list_done.render("Milk"),
),
),
list_style.copy()
.width(column_width - 1)
.render(
list_style.width(column_width - 1).render(
join_vertical(
position.left,
list_header.render("Programming Languages"),
Expand All @@ -182,9 +178,9 @@ fn build_history() -> String:

return join_horizontal(
position.top,
history_style.copy().alignment(position.right).render(history_a),
history_style.copy().alignment(position.center).render(history_b),
history_style.copy().margin_right(0).render(history_c),
history_style.alignment(position.right).render(history_a),
history_style.alignment(position.center).render(history_b),
history_style.margin_right(0).render(history_c),
)


Expand All @@ -196,17 +192,15 @@ fn build_status_bar() -> String:
var status_style = mog.new_style().foreground(mog.Color("#FFFDF5")).background(mog.Color("#FF5F87")).padding(0, 1)
# .margin_right(1)

var encoding_style = status_nugget_style.copy().background(mog.Color("#A550DF")).horizontal_alignment(
position.right
)
var encoding_style = status_nugget_style.background(mog.Color("#A550DF")).horizontal_alignment(position.right)

var status_text_style = status_bar_style.copy().padding_left(1)
var fish_cake_style = status_nugget_style.copy().background(mog.Color("#6124DF"))
var status_text_style = status_bar_style.padding_left(1)
var fish_cake_style = status_nugget_style.background(mog.Color("#6124DF"))

var status_key = status_style.render("STATUS")
var encoding = encoding_style.render("UTF-8")
var fish_cake = fish_cake_style.render("Fish Cake")
var status_val = status_text_style.copy().width(
var status_val = status_text_style.width(
width - get_width(status_key) - get_width(encoding) - get_width(fish_cake)
).render("Ravishing")

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/run.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import mog


var style = mog.new_style().horizontal_alignment(mog.center).vertical_alignment(mog.center).padding(0, 1)
var header_style = style.copy().foreground(mog.Color("#39E506"))
var header_style = style.foreground(mog.Color("#39E506"))


fn table_styling(row: Int, col: Int) -> mog.Style:
Expand Down
2 changes: 1 addition & 1 deletion examples/readme/basic.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from mog import Style
import mog


fn main() raises:
fn main():
var style = (
mog.new_style()
.bold(True)
Expand Down
30 changes: 12 additions & 18 deletions examples/readme/layout.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ fn build_tabs() -> String:

var tab_style = mog.new_style().border(tab_border).border_foreground(highlight).padding(0, 1)

var active_tab = tab_style.copy().border(active_tab_border, True)
var active_tab = tab_style.border(active_tab_border, True)

var tab_gap = tab_style.copy().border_top(False).border_left(False).border_right(False)
var tab_gap = tab_style.border_top(False).border_left(False).border_right(False)

var row = join_horizontal(
position.top,
Expand Down Expand Up @@ -84,7 +84,7 @@ fn build_dialog_box() -> String:
0, 3
).margin_top(1)

var active_button_style = button_style.copy().foreground(mog.Color("#FFF7DB")).background(
var active_button_style = button_style.foreground(mog.Color("#FFF7DB")).background(
mog.Color("#F25D94")
).margin_right(2).underline()

Expand Down Expand Up @@ -138,9 +138,7 @@ fn build_lists() -> String:
list_item.render("Pomelo"),
),
),
list_style.copy()
.width(column_width)
.render(
list_style.width(column_width).render(
join_vertical(
position.left,
list_header.render("Actual Lip Gloss Vendors"),
Expand All @@ -151,9 +149,7 @@ fn build_lists() -> String:
check_mark + list_done.render("Milk"),
),
),
list_style.copy()
.width(column_width - 1)
.render(
list_style.width(column_width - 1).render(
join_vertical(
position.left,
list_header.render("Programming Languages"),
Expand All @@ -180,9 +176,9 @@ fn build_history() -> String:

return join_horizontal(
position.top,
history_style.copy().alignment(position.right).render(history_a),
history_style.copy().alignment(position.center).render(history_b),
history_style.copy().margin_right(0).render(history_c),
history_style.alignment(position.right).render(history_a),
history_style.alignment(position.center).render(history_b),
history_style.margin_right(0).render(history_c),
)


Expand All @@ -194,17 +190,15 @@ fn build_status_bar() -> String:
var status_style = mog.new_style().foreground(mog.Color("#FFFDF5")).background(mog.Color("#FF5F87")).padding(0, 1)
# .margin_right(1)

var encoding_style = status_nugget_style.copy().background(mog.Color("#A550DF")).horizontal_alignment(
position.right
)
var encoding_style = status_nugget_style.background(mog.Color("#A550DF")).horizontal_alignment(position.right)

var status_text_style = status_bar_style.copy().padding_left(1)
var fish_cake_style = status_nugget_style.copy().background(mog.Color("#6124DF"))
var status_text_style = status_bar_style.padding_left(1)
var fish_cake_style = status_nugget_style.background(mog.Color("#6124DF"))

var status_key = status_style.render("STATUS")
var encoding = encoding_style.render("UTF-8")
var fish_cake = fish_cake_style.render("Fish Cake")
var status_val = status_text_style.copy().width(
var status_val = status_text_style.width(
width - get_width(status_key) - get_width(encoding) - get_width(fish_cake)
).render("Ravishing")

Expand Down
20 changes: 10 additions & 10 deletions examples/table/pokemon.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@
# # colors = DIM_TYPE_COLORS

# # var color = colors.get(data[row - 1][col], mog.Color("#FFFFFF"))
# # var copy_style = style.copy().foreground(color)
# # var copy_style = style.foreground(color)
# # return copy_style

# # if is_even:
# # var copy_style = style.copy().foreground(mog.Color("245"))
# # var copy_style = style.foreground(mog.Color("245"))
# # return copy_style

# # var copy_style = style.copy().foreground(mog.Color("252"))
# # var copy_style = style.foreground(mog.Color("252"))
# # return copy_style
# # return style_func

Expand All @@ -97,11 +97,11 @@
# # .padding_bottom(1) \
# # .padding_left(1)

# # var header_style = style.copy() \
# # var header_style = style \
# # .foreground(mog.Color("252")) \
# # .bold()

# # var selected_style = style.copy() \
# # var selected_style = style \
# # .foreground(mog.Color("#01BE85")) \
# # .background(mog.Color("#00432F"))

Expand All @@ -121,11 +121,11 @@
# .padding_bottom(1) \
# .padding_left(1)

# var header_style = style.copy() \
# var header_style = style \
# .foreground(mog.Color("252")) \
# .bold()

# var selected_style = style.copy() \
# var selected_style = style \
# .foreground(mog.Color("#01BE85")) \
# .background(mog.Color("#00432F"))

Expand All @@ -142,14 +142,14 @@
# colors = DIM_TYPE_COLORS

# var color = colors.get(data[row - 1][col], mog.Color("#FFFFFF"))
# var copy_style = style.copy().foreground(color)
# var copy_style = style.foreground(color)
# return copy_style

# if is_even:
# var copy_style = style.copy().foreground(mog.Color("245"))
# var copy_style = style.foreground(mog.Color("245"))
# return copy_style

# var copy_style = style.copy().foreground(mog.Color("252"))
# var copy_style = style.foreground(mog.Color("252"))
# return copy_style

# var border_style = mog.Style()
Expand Down
2 changes: 1 addition & 1 deletion mog/color.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct NoColor(TerminalColor):

Example usage:

var style = some_style.copy().background(NoColor())
var style = some_style.background(NoColor())
"""

fn color(self, renderer: Renderer) -> mist.AnyColor:
Expand Down
Loading
Loading