Skip to content

Commit

Permalink
feat: update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
brettkolodny committed Dec 31, 2023
1 parent d14554f commit 22eb85e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 36 deletions.
9 changes: 5 additions & 4 deletions gleam.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
name = "hug"
version = "0.1.2"
version = "1.0"
licences = ["Apache-2.0"]
description = "Helpful and pretty CLI messages"
repository = { type = "github", user = "brettkolodny", repo = "gleam-hug" }
gleam = ">= 0.32.0"
gleam = ">= 0.33.0"

[javascript.deno]
allow_read = ["./gleam.toml", "./test/"]

[dependencies]
gleam_stdlib = "~> 0.32.0"
gleam_community_ansi = "~> 1.2.0"
gleam_stdlib = "~> 0.34.0"
gleam_community_ansi = "~> 1.3"
gleam_community_colour = "~> 1.3"

[dev-dependencies]
gleeunit = "~> 1.0"
13 changes: 7 additions & 6 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_community_ansi", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_community_colour"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "8B5A9677BC5A2738712BBAF2BA289B1D8195FDF962BBC769569976AD5E9794E1" },
{ name = "gleam_community_colour", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "036C206886AFB9F153C552700A7A0B4D2864E3BC96A20C77E5F34A013C051BE3" },
{ name = "gleam_stdlib", version = "0.32.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "07D64C26D014CF570F8ACADCE602761EA2E74C842D26F2FD49B0D61973D9966F" },
{ name = "gleeunit", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D3682ED8C5F9CAE1C928F2506DE91625588CC752495988CBE0F5653A42A6F334" },
{ name = "gleam_community_ansi", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "AB7C3CCC894653637E02DC455D5890C8CF3064E83E78CFE61145A4C458D02DE6" },
{ name = "gleam_community_colour", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "A49A5E3AE8B637A5ACBA80ECB9B1AFE89FD3D5351FF6410A42B84F666D40D7D5" },
{ name = "gleam_stdlib", version = "0.34.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "1FB8454D2991E9B4C0C804544D8A9AD0F6184725E20D63C3155F0AEB4230B016" },
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
]

[requirements]
gleam_community_ansi = { version = "~> 1.2.0" }
gleam_stdlib = { version = "~> 0.32.0" }
gleam_community_ansi = { version = "~> 1.3" }
gleam_community_colour = { version = "~> 1.3" }
gleam_stdlib = { version = "~> 0.34.0" }
gleeunit = { version = "~> 1.0" }
90 changes: 64 additions & 26 deletions src/hug.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import gleam/int
import gleam/list
import gleam/result
import gleam/string
import gleam/option as o
import gleam_community/ansi

// TYPES ----------------------------------------------------------------------
Expand All @@ -44,6 +45,38 @@ type Output {
Info
}

pub opaque type HugBuilder {
HugBuilder(
file_name: o.Option(String),
source: o.Option(String),
start: o.Option(Location),
end: o.Option(Location),
message: o.Option(String),
hint: o.Option(String),
)
}

// pub type Options {
// Options
// }

// CONSTRUCTOR ----------------------------------------------------------------

// pub fn new() -> HugBuilder {
// HugBuilder(
// file_name: o.None,
// source: o.None,
// start: o.None,
// end: o.None,
// message: o.None,
// hint: o.None,
// )
// }

// pub fn with_file_name(builder: HugBuilder, file_name: String) -> HugBuilder {

// }

// OUTPUTS --------------------------------------------------------------------

/// Returns a `String` displaying the provided error and relevant code.
Expand Down Expand Up @@ -244,7 +277,7 @@ fn underline_source(
Info -> ansi.blue
}

use index, line <- list.index_map(source_lines)
use line, index <- list.index_map(source_lines)

let list_length = list.length(source_lines) - 1

Expand All @@ -271,10 +304,8 @@ fn underline_source(

let white_space = string.repeat(" ", num_white_space)

white_space <> colour(string.repeat(
"~",
end.col - num_white_space - 1,
))
white_space
<> colour(string.repeat("~", end.col - num_white_space - 1))
}

_ -> {
Expand Down Expand Up @@ -311,12 +342,17 @@ fn construct_body(
int.max(
string.length(int.to_string(start.row)),
string.length(int.to_string(end.row)),
) - 1
)
- 1

let body_start =
string.repeat(" ", left_padding) <> " ┌─ " <> file_name <> ":" <> int.to_string(
start.row,
) <> ":" <> int.to_string(start.col)
string.repeat(" ", left_padding)
<> " ┌─ "
<> file_name
<> ":"
<> int.to_string(start.row)
<> ":"
<> int.to_string(start.col)

let relevant_lines =
get_relevant_lines(string.split(source, on: "\n"), start, end)
Expand All @@ -327,10 +363,11 @@ fn construct_body(

let body =
list.zip(relevant_lines, underlines)
|> list.index_map(fn(index, input) {
|> list.index_map(fn(input, index) {
construct_output_line(
input,
index + start.row,
index
+ start.row,
trim_left_amount,
left_padding,
)
Expand All @@ -340,9 +377,11 @@ fn construct_body(
string.join(
[
body_start,
string.repeat(" ", left_padding) <> " │",
string.repeat(" ", left_padding)
<> " │",
body,
string.repeat(" ", left_padding) <> " │",
string.repeat(" ", left_padding)
<> " │",
],
"\n",
)
Expand All @@ -360,19 +399,18 @@ fn construct_output_line(
let line_number_padding = left_padding - string.length(int.to_string(row)) + 1

let source_line =
ansi.green(int.to_string(row)) <> string.repeat(" ", line_number_padding) <> " │ " <> trim_left(
source_line,
by: trim_left_amount,
)
ansi.green(int.to_string(row))
<> string.repeat(" ", line_number_padding)
<> " │ "
<> trim_left(source_line, by: trim_left_amount)

case string.length(underline) {
0 -> source_line
_ -> {
let underline_line =
string.repeat(" ", left_padding) <> " │ " <> trim_left(
underline,
by: trim_left_amount,
)
string.repeat(" ", left_padding)
<> " │ "
<> trim_left(underline, by: trim_left_amount)

string.join([source_line, underline_line], "\n")
}
Expand All @@ -382,7 +420,8 @@ fn construct_output_line(
//
fn get_trim_left_amount(lines: List(String)) -> Int {
let get_left_white_space = fn(line) {
string.length(line) - {
string.length(line)
- {
line
|> string.trim_left()
|> string.length()
Expand All @@ -393,16 +432,15 @@ fn get_trim_left_amount(lines: List(String)) -> Int {
list.first(lines)
|> result.unwrap("")

use min_white_space, line <- list.fold(
lines,
get_left_white_space(first_line),
use min_white_space, line <- list.fold(lines, get_left_white_space(first_line),
)

case string.trim(line) {
"" -> min_white_space
_ -> {
let white_space =
string.length(line) - {
string.length(line)
- {
line
|> string.trim_left()
|> string.length()
Expand Down

0 comments on commit 22eb85e

Please sign in to comment.