-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from jceaser/develop
Develop - major update
- Loading branch information
Showing
20 changed files
with
2,219 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*.go] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = space | ||
indent_size = 4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,9 @@ db | |
db2 | ||
iif | ||
isodate | ||
md2html | ||
roll | ||
rpn | ||
scale | ||
striper | ||
|
||
thru |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"bufio" | ||
"flag" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
type App_Data struct { | ||
verbose bool | ||
} | ||
|
||
var app_data = App_Data{verbose:false,} | ||
|
||
func AsColor(color [3]byte, text string) string { | ||
return fmt.Sprintf("\033[38;2;%d;%d;%dm%s\033[00m", | ||
color[0], color[1], color[2], text) | ||
return text | ||
} | ||
|
||
func ExpandColorText(color [3]byte) string { | ||
box := AsColor(color, "\uEE03\uEE04\uEE05") | ||
red := color[0] | ||
green := color[1] | ||
blue := color[2] | ||
return fmt.Sprintf("%s%00x%0x%0x", box, red, green, blue) | ||
} | ||
|
||
/******************************************************************************/ | ||
/* Application Tasks */ | ||
|
||
/* Make sure that a supplied value in the byte range of 0-255 */ | ||
func ColorLimits(value int) byte { | ||
var ret byte | ||
|
||
if value>255 { | ||
ret = 255 | ||
} else if value < 0 { | ||
ret = 0 | ||
} else { | ||
ret = byte(value) | ||
} | ||
return ret | ||
} | ||
|
||
func ValueToNumber(reader *bufio.Reader, fallback byte) byte { | ||
var ret byte | ||
text, read_err := reader.ReadString('\n') | ||
if read_err != nil { | ||
fmt.Fprintf(os.Stderr, "ReadString: %s", read_err) | ||
} | ||
text = strings.Trim(text, "\t \n") | ||
value, err := strconv.Atoi(text) | ||
if err == nil { | ||
ret = ColorLimits(value) | ||
} else { | ||
fmt.Fprintf(os.Stderr, "Bad value [%s] using fallback: %d", text, | ||
fallback) | ||
ret = fallback | ||
} | ||
return ret | ||
} | ||
|
||
func AskForNumbers() [3]byte { | ||
reader := bufio.NewReader(os.Stdin) | ||
|
||
fmt.Println ("Enter in a value between 0 and 255 and press enter:") | ||
|
||
fmt.Print ("\nRed> ") | ||
red := ValueToNumber(reader, 255) | ||
|
||
fmt.Print ("\nGreen> ") | ||
green := ValueToNumber(reader, 255) | ||
|
||
fmt.Print ("\nBlue> ") | ||
blue := ValueToNumber(reader, 255) | ||
fmt.Println() | ||
|
||
return [3]byte{red, green, blue} | ||
} | ||
|
||
func FindCompliment(color [3]byte) [3]byte{ | ||
color[0] = 255 - color[0] | ||
color[1] = 255 - color[1] | ||
color[2] = 255 - color[2] | ||
return color | ||
} | ||
|
||
func ExampleLine(color [3]byte) string { | ||
compliment := FindCompliment(color) | ||
color_text := ExpandColorText(color) | ||
compliment_text := ExpandColorText(compliment) | ||
|
||
return fmt.Sprintf ("%s->%s\n", color_text, compliment_text) | ||
} | ||
|
||
/******************************************************************************/ | ||
/* Command Tasks */ | ||
|
||
func main() { | ||
Check failure on line 103 in color.go
|
||
verbose := flag.Bool("verbose", false, "verbose") | ||
flag.Parse() | ||
|
||
app_data.verbose = *verbose | ||
|
||
color := AskForNumbers() | ||
fmt.Printf(ExampleLine(color)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,66 @@ | ||
// This command will report on the width and/or hight of the console | ||
|
||
package main | ||
|
||
import ("fmt" | ||
/*"bufio" | ||
"os" | ||
"io" | ||
"bytes"*/ | ||
import ( | ||
"fmt" | ||
"flag" | ||
"syscall" | ||
"unsafe" | ||
) | ||
|
||
/****/ | ||
/******************************************************************************/ | ||
// MARK: Structures | ||
|
||
type winsize struct { | ||
Check failure on line 15 in console.go
|
||
Row uint16 | ||
Col uint16 | ||
Xpixel uint16 | ||
Ypixel uint16 | ||
} | ||
|
||
const ( | ||
ESC_SAVE_SCREEN = "?47h" | ||
ESC_RESTORE_SCREEN = "?47l" | ||
|
||
ESC_SAVE_CURSOR = "s" | ||
ESC_RESTORE_CURSOR = "u" | ||
|
||
ESC_BOLD_ON = "1m" | ||
ESC_BOLD_OFF = "0m" | ||
|
||
ESC_CURSOR_ON = "?25h" | ||
ESC_CURSOR_OFF = "?25l" | ||
|
||
ESC_CLEAR_SCREEN = "2J" | ||
ESC_CLEAR_LINE = "2K" | ||
) | ||
/******************************************************************************/ | ||
// MARK: - Functions | ||
|
||
func getWidth() uint { | ||
func GetWidth() uint { | ||
ws := &winsize{} | ||
retCode, _, errno := syscall.Syscall(syscall.SYS_IOCTL, | ||
uintptr(syscall.Stdin), | ||
uintptr(syscall.TIOCGWINSZ), | ||
uintptr(unsafe.Pointer(ws))) | ||
|
||
if int(retCode) == -1 { | ||
panic(errno) | ||
} | ||
return uint(ws.Col) | ||
} | ||
|
||
func getHeight() uint { | ||
func GetHeight() uint { | ||
ws := &winsize{} | ||
retCode, _, errno := syscall.Syscall(syscall.SYS_IOCTL, | ||
uintptr(syscall.Stdin), | ||
uintptr(syscall.TIOCGWINSZ), | ||
uintptr(unsafe.Pointer(ws))) | ||
|
||
if int(retCode) == -1 { | ||
panic(errno) | ||
} | ||
return uint(ws.Row) | ||
} | ||
|
||
|
||
/****/ | ||
|
||
/******************************************************************************/ | ||
// MARK: - Application | ||
|
||
func main() { | ||
//args := os.Args | ||
|
||
bothMode := flag.Bool("both", true, "display both width and height") | ||
heightMode := flag.Bool("height", false, "height mode") | ||
widthMode := flag.Bool("width", false, "width mode") | ||
heightMode := flag.Bool("height", false, "Height mode") | ||
widthMode := flag.Bool("width", false, "Width mode") | ||
adjust := flag.Int("adjust", 0, "Value to add to height or width") | ||
|
||
flag.Parse() | ||
|
||
if *bothMode { | ||
fmt.Printf("%dx%d\n", getWidth(), getHeight()) | ||
} else if *heightMode {//only first and last | ||
fmt.Printf("%d\n", getHeight()) | ||
if *heightMode { | ||
fmt.Printf("%d\n", GetHeight() + uint(*adjust)) | ||
} else if *widthMode { | ||
fmt.Printf("%d\n", getWidth()) | ||
fmt.Printf("%d\n", GetWidth() + uint(*adjust)) | ||
} else { | ||
fmt.Printf("%dx%d\n", GetWidth(), GetHeight()) | ||
} | ||
} |
Oops, something went wrong.