Skip to content

Commit

Permalink
Merge pull request imdrasil#19 from imdrasil/add-fallbacks-to-check-t…
Browse files Browse the repository at this point in the history
…erminal-width

Add fallbacks if OS has no tput
  • Loading branch information
imdrasil authored Sep 13, 2021
2 parents 5608ed7 bf976e3 commit fe30d61
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 10,7 @@ Add this to your application's `shard.yml`:
dependencies:
sam:
github: imdrasil/sam.cr
version: 0.4.1
version: 0.4.2
```
After executing `shards install` Sam-file will be added to the root of your project (unless you already have one).
Expand Down
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 1,5 @@
name: sam
version: 0.4.1
version: 0.4.2

authors:
- Roman Kalnytskyi <[email protected]>
Expand Down
2 changes: 2 additions & 0 deletions src/sam.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,8 @@ require "./sam/*"
module Sam
extend Execution

VERSION = "0.4.2"

# Task separation symbol used in command line.
TASK_SEPARATOR = "@"

Expand Down
24 changes: 22 additions & 2 deletions src/sam/shell_table.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 8,7 @@ module Sam
getter tasks : Array(Task), width : Int32

def initialize(@tasks)
@width = `tput cols`.to_i
@width = terminal_width
end

def generate
Expand All @@ -18,6 18,26 @@ module Sam
end
end

private def terminal_width
if has_tput?
`tput cols`.to_i
elsif has_stty?
`stty size`.chomp.split(' ')[1].to_i
else
80
end
end

private def has_tput?
!`which tput`.empty?
end

private def has_stty?
return false if `which stty`.empty?

/\d* \d*/.matches?(`stty size`)
end

private def write_header(io)
io << "Name".ljust(name_column_width) << " Description\n"
io << "-" * name_column_width << BORDER << "-" * description_column_width << "\n"
Expand Down Expand Up @@ -59,7 79,7 @@ module Sam
].min.to_i.as(Int32)
end

def description_column_width
private def description_column_width
@description_column_width ||= (clean_width - name_column_width).as(Int32)
end

Expand Down
3 changes: 0 additions & 3 deletions src/sam/version.cr

This file was deleted.

0 comments on commit fe30d61

Please sign in to comment.