Skip to content

Commit

Permalink
readying initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
endowdly committed Jun 16, 2022
1 parent 58c53b9 commit 29ec4a7
Show file tree
Hide file tree
Showing 11 changed files with 564 additions and 135 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ __pycache__/
*.pyc

# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
tools/**
!tools/packages.config

# Tabs Studio
*.tss
Expand Down Expand Up @@ -458,4 +458,4 @@ $RECYCLE.BIN/
paket-files/

# Playgrounds
playground.fsx
playground.fsx
15 changes: 6 additions & 9 deletions Configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ open System
open System.IO
open System.Text

module Configuration =

module Configuration =
open FSharp.Json

[<Literal>]
Expand Down Expand Up @@ -125,7 +124,7 @@ module Configuration =

let defaultConfigFile =
try
// note on the difference between known folder calls
// Note on the difference between known folder calls:
// in go, the xdg package adds the config to LocalAppData for Win and xdg_config_home for unix
// in .net core, to link to xdg_config_home, use ApplicationData
// ApplicationData also links to AppData/Roaming, which is the correct heirarchy for
Expand Down Expand Up @@ -161,8 +160,6 @@ module Configuration =

let saveDefault () = save defaultConfig

// todo better error handling
// idea return result<config, ex>
let load =

// If no configuration file exists, create one
Expand All @@ -178,14 +175,14 @@ module Configuration =
| Config data ->
// Check version and validate in place
if data.ConfigVersion = ConfigVersion then
data, false
data
else
defaultConfig, true
defaultConfig

| ConfigFail _ ->
eprintfn "Could not deserialize config, using default"
defaultConfig, true
defaultConfig

| AccessDenied ->
eprintfn "Could not load config file, using default"
defaultConfig, true
defaultConfig
2 changes: 1 addition & 1 deletion GroundTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module GroundTypes =
| Italic
| Strikethrough

/// A compound type to hold all the SGR attributes
/// A record to hold all the SGR attributes
type Style =
{ Foreground : Color option
Background : Color option
Expand Down
35 changes: 20 additions & 15 deletions Helper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@ open System.Drawing

module Helper =

let rec times (from : DateTime) (toTime : DateTime) =
/// tickGen creates an infinite sequence of ticks from .. toTime
let rec tickGen (from : DateTime) (toTime : DateTime) =
seq {
if from <= toTime then
yield from
yield! times (from.AddTicks(1)) toTime
yield! tickGen (from.AddTicks(1)) toTime
}

// These functions will let us turn our json unfriedly types into core types
// idea maybe bind to a Result for parseTimeZone
// todo -> Result
// These functions will change json configuration types into standard types

/// Tries to find a timezone by string. On failure, returns the local timezone.
let tryGetTimeZone s =
try
TimeZoneInfo.FindSystemTimeZoneById(s)
with
| _ ->
eprintfn $"Could not find timezone '{s}, defaulting to system timezone"
TimeZone.Local
TimeZone.Local

// todo -> Result
/// Tries to find a color by string or hex code. On failure, returns None.
let tryGetColor =
function
| "" -> None
Expand All @@ -35,29 +36,33 @@ module Helper =
eprintfn $"{s} is not a known color or html hex color, using default color"
None

/// Formats time in a custom way.
let formatTime b (t : DateTime) =
// standard formatters are locale specific so we must use custom formatters to enforce a style
// Standard formatters are locale specific so we must use custom formatters to enforce a style
// link https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings

if b then t.ToString("h:mmtt") else t.ToString("HH:mm")

let formatDay (t : DateTime) = t.ToString("ddd dd MMM yyyy")
let formatDateTime b (t : DateTime) = (formatDay t) + " " + (formatTime b t)
/// Formats date information in a custom way.
let formatDay (t : DateTime) = t.ToString("ddd dd MMM yyyy")
/// Returns a custom date and time string.
let formatDateTime b (t : DateTime) = (formatDay t) + " " + (formatTime b t)

// todo -> Result
/// Converts a universal time to a different timezone.
let toTimeZone t tz =
try
TimeZoneInfo.ConvertTimeFromUtc(t, tz)
with
| _ ->
eprintfn $"Could not convert to {tz.ToString()} using local"
eprintfn $"Could not convert to {tz.ToString()}, using input"
t

module ConsoleHelper =
let useAlternateScreenBuffer() = printf "\u001b[?1049h"
let useMainScreenBuffer() = printf "\u001b[?1049l"
let useAlternateScreenBuffer () = printf "\u001b[?1049h"
let useMainScreenBuffer () = printf "\u001b[?1049l"

(*
module Native =
open System
open System.Runtime.InteropServices
Expand Down Expand Up @@ -97,4 +102,4 @@ module ConsoleHelper =
let useAlternateScreenBuffer = printf "\u001b[?1049h"
let useMainScreenBuffer = printf "\u001b[?1049l"
*)
*)
34 changes: 25 additions & 9 deletions Plot.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,38 @@ namespace fitz

open System

module Plot =

module Plot =
open Configuration
open Helper

[<Literal>]
let SymbolRectanglesDay = '█'

[<Literal>]
let SymbolRectanglesTwilight = '▒'

[<Literal>]
let SymbolRectanglesNight = ' '

[<Literal>]
let SymbolMono = '#'

[<Literal>]
let SymbolBork = '!'

[<Literal>]
let CharBar = '|'

[<Literal>]
let CharCaret = '^'

[<Literal>]
let SymbolSunMoonTwilight = '☼'

[<Literal>]
let SymbolSunMoonDay = '☀'

[<Literal>]
let SymbolSunMoonNight = '☾'

let configLocationToLocation x : Location = { Name = x.Name; TimeZone = tryGetTimeZone x.TimeZone }
Expand Down Expand Up @@ -104,13 +122,11 @@ module Plot =
let utc = t.ToUniversalTime()
let styleNormal = normalStyle cfg
let style =
match cfg.Style.Colorize with
| false -> (fun _ -> styleNormal)
| true -> getStyle cfg
if cfg.Style.Colorize then getStyle cfg else (fun _ -> styleNormal)

let w =
if cfg.Stretch then
Console.WindowWidth
Console.WindowWidth - 1
else
Console.WindowWidth * 13 / 21 // approx golden ratio

Expand All @@ -119,15 +135,15 @@ module Plot =
let minOffset = minPerSlot * w / 2
let timeSlot = [| for t in 0 .. w -> utc.AddMinutes(float <| t * minPerSlot - minOffset) |]

// note determining this programmatically can take a bit of time
// Note determining this programmatically can take a bit of time:
// this has to generate and check every tick in a second -- we can speed up execution
// by shrinking the check range or eliminate it by passing a boolean like: plotTime c t b
// just have Args.parseFlags emit a bool at the end to pass to here
// the longest time will be when an arbitrary time is passed
// Seq.contains (lazy) bails if it finds a generated match so 'now' execution will be fast
let markerStr =
let plusOne = t.AddSeconds(1.0)
let inTime = times t plusOne |> Seq.contains DateTime.Now
let inTime = tickGen t plusOne |> Seq.contains DateTime.Now
if inTime then "now" else "time"

let markerStrSeg = Segment.fromString markerStr
Expand Down Expand Up @@ -213,7 +229,7 @@ module Plot =
ticLine[pos] <- tic
Segment.insertCellsInPlace pos hourCell numberLine)

// note wanted to do tics more 'cleverly' but couldn't think of an improvement
// Note wanted to do tics more 'cleverly' but couldn't think of an improvement

let rows = markerSeg :: List.concat timebars

Expand Down
Loading

0 comments on commit 29ec4a7

Please sign in to comment.