Skip to content
This repository has been archived by the owner on Feb 3, 2024. It is now read-only.

Commit

Permalink
Format fixes followup (#43)
Browse files Browse the repository at this point in the history
* Fixed warnings and tests errors

* Followup PR with format fixes

* Fixes for V fmt and tests
  • Loading branch information
rodabt committed Jun 20, 2023
1 parent 630107e commit 89f2ca4
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 105 deletions.
92 changes: 0 additions & 92 deletions styles.v
Original file line number Diff line number Diff line change
@@ -1,97 +1,5 @@
module termtable

const (
gridline = Sepline{
left: '+'
right: '+'
cross: '+'
sep: '-'
}
style_configs = {
'grid': StyleConfig{
topline: gridline
headerline: gridline
middleline: gridline
bottomline: gridline
colsep: '|'
}
'plain': StyleConfig{
colsep: ' '
}
'simple': StyleConfig{
headerline: Sepline{
cross: ' '
sep: '-'
}
fill_padding: false
colsep: ' '
}
'pretty': StyleConfig{
topline: gridline
headerline: gridline
bottomline: gridline
colsep: '|'
}
'fancy_grid': StyleConfig{
topline: Sepline{
left: '╒'
right: '╕'
cross: '╤'
sep: '═'
}
headerline: Sepline{
left: '╞'
right: '╡'
cross: '╪'
sep: '═'
}
middleline: Sepline{
left: '├'
right: '┤'
cross: '┼'
sep: '─'
}
bottomline: Sepline{
left: '╘'
right: '╛'
cross: '╧'
sep: '═'
}
colsep: '│'
}
'md': StyleConfig{
headerline: Sepline{
left: '|'
right: '|'
cross: '|'
sep: '-'
}
colsep: '|'
}
'rst': StyleConfig{
topline: Sepline{
left: ''
right: ''
cross: ''
sep: '='
}
headerline: Sepline{
left: ''
right: ''
cross: ''
sep: '='
}
bottomline: Sepline{
left: ''
right: ''
cross: ''
sep: '='
}
fill_padding: false
}
}
)

pub enum Style {
custom
plain
Expand Down
4 changes: 0 additions & 4 deletions styles_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ module termtable

import os

const (
dir = os.dir(@FILE)
)

fn test_table_styles() {
custom_style := StyleConfig{
headerline: Sepline{
Expand Down
106 changes: 101 additions & 5 deletions termtable.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,101 @@
module termtable

import os

const dir = os.dir(@FILE)

const (
gridline = Sepline{
left: '+'
right: '+'
cross: '+'
sep: '-'
}
style_configs = {
'grid': StyleConfig{
topline: gridline
headerline: gridline
middleline: gridline
bottomline: gridline
colsep: '|'
}
'plain': StyleConfig{
colsep: ' '
}
'simple': StyleConfig{
headerline: Sepline{
cross: ' '
sep: '-'
}
fill_padding: false
colsep: ' '
}
'pretty': StyleConfig{
topline: gridline
headerline: gridline
bottomline: gridline
colsep: '|'
}
'fancy_grid': StyleConfig{
topline: Sepline{
left: '╒'
right: '╕'
cross: '╤'
sep: '═'
}
headerline: Sepline{
left: '╞'
right: '╡'
cross: '╪'
sep: '═'
}
middleline: Sepline{
left: '├'
right: '┤'
cross: '┼'
sep: '─'
}
bottomline: Sepline{
left: '╘'
right: '╛'
cross: '╧'
sep: '═'
}
colsep: '│'
}
'md': StyleConfig{
headerline: Sepline{
left: '|'
right: '|'
cross: '|'
sep: '-'
}
colsep: '|'
}
'rst': StyleConfig{
topline: Sepline{
left: ''
right: ''
cross: ''
sep: '='
}
headerline: Sepline{
left: ''
right: ''
cross: ''
sep: '='
}
bottomline: Sepline{
left: ''
right: ''
cross: ''
sep: '='
}
fill_padding: false
}
}
)

pub enum HeaderStyle {
plain
bold
Expand Down Expand Up @@ -38,7 +134,7 @@ pub mut:
// str generates the string representation of the table.
pub fn (t Table) str() string {
validate_table_properties(t) or {
eprintln('termtable: $err')
eprintln('termtable: ${err}')
exit(1)
}
edata := expand_tabs(t.data, t.tabsize)
Expand All @@ -60,7 +156,7 @@ pub fn (t Table) str() string {
bottomline := create_sepline(.bottom, colmaxes, t.padding, sc)
mut final_str := topline
for i, row_str in rowstrings {
final_str += '$row_str\n'
final_str += '${row_str}\n'
if i == 0 && rowstrings.len >= 2 {
final_str += headline
} else if i < rowstrings.len - 1 {
Expand All @@ -76,10 +172,10 @@ fn validate_table_properties(t Table) ! {
return error('Table.data should not be empty.')
}
if t.tabsize < 2 {
return error('tabsize should be at least 2 (got $t.tabsize).')
return error('tabsize should be at least 2 (got ${t.tabsize}).')
}
if t.padding < 0 {
return error('cannot use a negative padding (got $t.padding).')
return error('cannot use a negative padding (got ${t.padding}).')
}
if t.style == .custom {
default_sc := StyleConfig{}
Expand Down Expand Up @@ -146,7 +242,7 @@ fn apply_header_style(row []string, style HeaderStyle, orient Orientation) []str
r << row[1..]
return r
}
return row.map('\e[1m$it\e[0m')
return row.map('\e[1m${it}\e[0m')
}

fn get_row_spaces(row []string, col_sizes []int) []int {
Expand Down
4 changes: 0 additions & 4 deletions unicode_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ module termtable

import os

const (
dir = os.dir(@FILE)
)

fn test_cjk_chars() {
table := Table{
data: [
Expand Down

0 comments on commit 89f2ca4

Please sign in to comment.