package
1.2.12
Repository: https://github.com/cpmech/gosl.git
Documentation: pkg.go.dev

# README

Gosl. io. Input/output, read/write files, and print commands

Go Reference

This sub-package helps with reading and writing files, printing nice formatted messages (with colours), and parsing strings.

Examples

Read and write files

To write and read a file:

theline := "Hello World !!!"
io.WriteFileSD("/tmp/gosl", "filestring.txt", theline)

f, err := io.OpenFileR("/tmp/gosl/filestring.txt")
if err != nil {
    chk.Panic("%v", err)
}

io.ReadLinesFile(f, func(idx int, line string) (stop bool) {
    Pforan("line = %v\n", line)
    chk.String(tst, line, theline)
    return
})

API

Please see the documentation here

# Functions

AppendToFile appends data to an existent (or new) file.
ArgsTable prints a nice table with input arguments Input: title -- title of table; e.g.
ArgToBool parses an argument as a boolean value Input: idxArg -- index of argument; e.g.
ArgToFilename parses an argument as a filename Input: idxArg -- index of argument; e.g.
ArgToFloat parses an argument as a float64 value Input: idxArg -- index of argument; e.g.
ArgToInt parses an argument as an integer value Input: idxArg -- index of argument; e.g.
ArgToString parses an argument as a string Input: idxArg -- index of argument; e.g.
Atob converts string to bool.
Atof converts string to float64.
Atoi converts string to integer.
Btoa converts flag to string Note: true => "true" false => "false".
Btoi converts flag to interger Note: true => 1 false => 0.
CopyFileOver copies file (Linux only with cp), overwriting if it exists already.
DblSf is the Sprintf for a slice of float64 (without brackets).
ExtractStrPair extracts the pair from, e.g., "key:val" Note: it returns empty strings if any is not found.
Ff wraps Fprintf.
FnExt returns the extension of a file name.
FnKey returns the file name key (without path and extension, if any).
IntSf is the Sprintf for a slice of integers (without brackets).
Itob converts from integer to bool Note: only zero returns false anything else returns true.
JoinKeys join keys separeted by spaces.
JoinKeys3 joins keys from 3 slices into a string with sets separated by sep and keys separeted by spaces.
JoinKeys4 joins keys from 4 slices into a string with sets separated by sep and keys separeted by spaces.
JoinKeysPre join keys separeted by spaces with a prefix.
Keycode extracts a keycode from a string such as "!typeA:keycodeA !typeB:keycodeB!typeC:keycodeC" Note: String == "!keyA !typeB:valB" is also valid.
Keycodes extracts keys from a keycode (extra) string Example: "!keyA !typeB:valB" => keycodes = [keyA, typeB].
NewDecoder returns a new decoder.
NewEncoder returns a new encoder.
OpenFileR opens a file for reading data.
PathKey returns the full path except the extension.
Pf prints formatted string.
Pfblue prints formatted string in blue.
PfBlue prints formatted string in high intensity blue.
Pfblue2 prints formatted string in another shade of blue.
Pfcyan prints formatted string in cyan.
PfCyan prints formatted string in high intensity cyan.
Pfcyan2 prints formatted string in another shade of cyan.
Pfdgreen prints formatted string in dark green.
Pfdyel prints formatted string in dark yellow.
Pfdyel2 prints formatted string in another shade of dark yellow.
Pfgreen prints formatted string in green.
PfGreen prints formatted string in high intensity green.
Pfgreen2 prints formatted string in another shade of green.
Pfgrey prints formatted string in grey.
Pfgrey2 prints formatted string in another shade of grey.
Pflmag prints formatted string in light magenta.
Pfmag prints formatted string in magenta.
PfMag prints formatted string in high intensity magenta.
Pforan prints formatted string in orange.
Pfpink prints formatted string in pink.
Pfpurple prints formatted string in purple.
Pfred prints formatted string in red.
PfRed prints formatted string in high intensity red.
PfWhite prints formatted string in high intensity white.
Pfyel prints formatted string in yellow.
PfYel prints formatted string in high intensity yellow.
Pipeline strings together the given exec.Cmd commands in a similar fashion to the Unix pipeline.
Pl prints new line.
ReadFile reads bytes from a file.
ReadLines reads lines from a file and calls ReadLinesCallback to process each line being read.
ReadLinesFile reads lines from a file and calls ReadLinesCallback to process each line being read.
ReadMatrix reads a text file in which the float64 type of numeric values represent a matrix of data.
ReadTable reads a text file in which the first line contains the headers and the next lines the float64 type of numeric values.
RemoveAll deletes all files matching filename specified by key (be careful).
RunCmd runs external command.
Sf wraps Sprintf.
SplitFloats splits space-separated float numbers.
SplitInts splits space-separated integers.
SplitKeys splits keys separeted by spaces.
SplitKeys3 splits a string with three sets of keys separated by comma.
SplitKeys4 splits a string with four sets of keys separated by comma.
SplitSpacesQuoted splits string with quoted substrings.
SplitWithinParentheses extracts arguments (substrings) within brackets e.g.: "(arg1, (arg2.1, arg2.2), arg3, arg4, (arg5.1,arg5.2, arg5.3 ) )".
StrSf is the Sprintf for a slice of string (without brackets).
StrSpaces returns a line with spaces.
StrThickLine returns a thick line (using '=').
StrThinLine returns a thin line (using '-').
UnColor removes console characters used to show colors.
WriteBytesToFile writes slice of bytes to a new file.
WriteBytesToFileD writes slice of bytes to a new file after creating a directory.
WriteBytesToFileVD writes slice of bytes to a new file, and print message, after creating a directory.
WriteFile writes data to a new file with given bytes.Buffer(s).
WriteFileD writes data to a new file after creating a directory.
WriteFileV writes data to a new file, and shows message.
WriteFileVD writes data to a new file, and shows message after creating a directory.
WriteStringToFile writes string to a new file.
WriteStringToFileD writes string to a new file after creating a directory.
WriteTableVD writes a text file in which the first line contains the headers, and the next lines contain the numeric values (float64).

# Variables

ColorsOn activates use of colors on console.
Verbose activates display of messages on console.

# Interfaces

Decoder defines decoders; e.g.
Encoder defines encoders; e.g.

# Type aliases

ReadLinesCallback is used in ReadLines to process line by line during reading of a file.