styled text outputed

This commit is contained in:
array-in-a-matrix 2024-02-26 15:53:28 -05:00
parent ec084ce210
commit cfd70851c6
2 changed files with 17 additions and 15 deletions

View file

@ -1,4 +1,4 @@
import strutils, os, procedures
import strutils, os, procedures, terminal
var argument: string
@ -12,11 +12,12 @@ if "dot" in args or "d" in args:
elif "cross" in args or "c" in args:
cross()
else:
echo "Would you like to preform the dot or cross product?"
styledEcho resetStyle, "Would you like to preform the ", styleBright, "dot ", resetStyle, "or ", styleBright, "cross ", resetStyle, "product?"
case toLowerAscii(readLine(stdin)):
of "dot", "d":
dot()
of "cross", "c":
cross()
else:
quit "Invalid operation!", QuitFailure
styledEcho fgRed, "Invalid operation!"
quit QuitFailure

View file

@ -1,4 +1,4 @@
import strutils, sequtils
import strutils, sequtils, terminal
#? validate if user input is of correct type
proc getInt: int =
@ -6,7 +6,7 @@ proc getInt: int =
try:
return parseInt(readline(stdin))
except:
echo "Please enter an integer, try again."
styledEcho resetStyle, "Please enter an ", styleBright, "integer, " , resetStyle, "try again."
#? validate if user input is of correct type
proc getFloat: float =
@ -14,7 +14,7 @@ proc getFloat: float =
try:
return parseFloat(readline(stdin))
except:
echo "Please enter a number, try again."
styledEcho resetStyle, "Please enter a ", styleBright, "number, " , resetStyle, "try again."
#? prints a matrix to the standard output
proc printMatrix*(matrix: seq[seq[float]]) =
@ -43,7 +43,8 @@ proc calcDot(matrix1: seq[seq[float]], matrix2: seq[seq[float]]): seq[seq[float]
col = col2
row = row1
else:
quit "Matrix dimensions mismatched, operation invalid!", QuitFailure
styledEcho fgRed, "Matrix dimensions mismatched!"
quit QuitFailure
var matrix = newSeqWith(row, newSeq[float](col))
@ -61,12 +62,12 @@ proc calcCross(vector1: array[3, float], vector2: array[3, float]): array[3, flo
result = [i, j, k]
proc dot* =
echo "MATRIX DOT PRODUCT"
styledEcho styleBright, "Matrix Dot Product"
#? record first matrix
echo "Enter number of rows in the first matrix:"
styledEcho "Enter number of ", styleBright, "rows ", resetStyle, "in the first matrix:"
let r1: int = getInt()
echo "Enter number of columns in the first matrix:"
styledEcho "Enter number of ", styleBright, "columns ", resetStyle, "in the first matrix:"
let c1: int = getInt()
var m1 = newSeqWith(r1, newSeq[float](c1))
procedures.fillMatrix(m1, r1, c1)
@ -74,9 +75,9 @@ proc dot* =
echo ""
#? record second matrix
echo "Enter number of rows in the second matrix:"
styledEcho "Enter number of ", styleBright, "rows ", resetStyle, "in the second matrix:"
let r2: int = getInt()
echo "Enter number of columns in the second matrix:"
styledEcho "Enter number of ", styleBright, "columns ", resetStyle, "in the second matrix:"
let c2: int = getInt()
var m2 = newSeqWith(r2, newSeq[float](c2))
procedures.fillMatrix(m2, r2, c2)
@ -93,7 +94,7 @@ proc dot* =
printMatrix(m)
proc cross* =
echo "VECTOR CROSS PRODUCT"
styledEcho styleBright, "Vector Cross Product"
type
VECTOR = array[3, float]
@ -101,12 +102,12 @@ proc cross* =
v1: VECTOR
v2: VECTOR
echo "Enter numbers in the first vector:"
styledEcho "Enter numbers in the ", styleBright, "first ", resetStyle, "vector:"
for i in 0..2:
echo "Enter item:"
v1[i] = getFloat()
echo "Enter numbers in the second vector:"
styledEcho "Enter numbers in the ", styleBright, "second ", resetStyle, "vector:"
for i in 0..2:
echo "Enter item:"
v2[i] = getFloat()