< Summary

Information
Class: Punch.CLI.PunchSession
Assembly: punch
File(s): /home/runner/work/punch/punch/src/Punch.CLI/PunchSession.cs
Line coverage
97%
Covered lines: 42
Uncovered lines: 1
Coverable lines: 43
Total lines: 80
Line coverage: 97.6%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Schedule()100%11100%
get_WorkingDate()100%11100%
get_FilePath()100%210%
get_TargetHours()100%11100%
get_Blocks()100%11100%
get_InputBuffer()100%11100%
get_InputCursor()100%11100%
get_TicketBuffer()100%11100%
get_TicketCursor()100%11100%
get_ActiveField()100%11100%
get_CursorSlot()100%11100%
get_SelectionLength()100%11100%
get_SelectedBlock()100%11100%
get_Editing()100%11100%
get_ShowHelp()100%11100%
get_ShowTicketSummary()100%11100%
get_LogScrollOffset()100%11100%
get_ShowTicketPicker()100%11100%
get_TicketPickerCursor()100%11100%
get_Tickets()100%11100%
get_IsInputActive()100%22100%
get_ActiveBuffer()100%22100%
get_ActiveCursor()100%22100%
set_ActiveCursor(...)100%22100%
ResetInput()100%11100%

File(s)

/home/runner/work/punch/punch/src/Punch.CLI/PunchSession.cs

#LineLine coverage
 1using System.Text;
 2
 3namespace Punch.CLI;
 4
 5// Holds the mutable editor state for a single day's TUI session: the schedule
 6// being edited, the input fields, the cursor/selection, and the view toggles.
 7// The event loop mutates these in place and the renderer reads them.
 8internal sealed class PunchSession
 9{
 8410    public PunchSession(DaySchedule schedule, DateOnly workingDate, string filePath, int cursorSlot, int targetHours = 8
 8411    {
 8412        Schedule = schedule;
 8413        WorkingDate = workingDate;
 8414        FilePath = filePath;
 8415        CursorSlot = cursorSlot;
 8416        TargetHours = targetHours;
 8417    }
 18
 34719    public DaySchedule Schedule { get; }
 520    public DateOnly WorkingDate { get; }
 021    public string FilePath { get; }
 22
 23    // The daily workday goal in whole hours, used for the status-bar percentage.
 224    public int TargetHours { get; }
 25
 1426    public IReadOnlyList<TimeBlock> Blocks => Schedule.Blocks;
 27
 28    // Input fields. ActiveField: 0 = Description, 1 = Ticket.
 31329    public StringBuilder InputBuffer { get; } = new();
 27130    public int InputCursor { get; set; }
 19231    public StringBuilder TicketBuffer { get; } = new();
 10432    public int TicketCursor { get; set; }
 50533    public int ActiveField { get; set; }
 34
 35    // Cursor / selection on the timeline.
 25236    public int CursorSlot { get; set; }
 20537    public int SelectionLength { get; set; } = 1; // number of 15-min slots (min 1)
 45638    public TimeBlock? SelectedBlock { get; set; }
 17839    public bool Editing { get; set; }
 40
 41    // View toggles.
 22442    public bool ShowHelp { get; set; }
 20343    public bool ShowTicketSummary { get; set; }
 50944    public int LogScrollOffset { get; set; }
 45
 46    // Ticket picker overlay. Tickets is reloaded from disk each time the picker
 47    // is opened, so edits to ~/.punch/tickets.txt are picked up without a restart.
 23848    public bool ShowTicketPicker { get; set; }
 2549    public int TicketPickerCursor { get; set; }
 10350    public List<TicketEntry> Tickets { get; set; } = new();
 51
 52    // Text input is editable when composing a new entry (no block selected) or
 53    // editing an existing one.
 8554    public bool IsInputActive => SelectedBlock == null || Editing;
 55
 56    // The buffer/cursor for whichever field currently has focus.
 13257    public StringBuilder ActiveBuffer => ActiveField == 0 ? InputBuffer : TicketBuffer;
 58
 59    public int ActiveCursor
 60    {
 15261        get => ActiveField == 0 ? InputCursor : TicketCursor;
 62        set
 8063        {
 14564            if (ActiveField == 0) InputCursor = value;
 1565            else TicketCursor = value;
 8066        }
 67    }
 68
 69    // Clears both input fields and returns focus to the Description field,
 70    // leaving edit mode. Does not touch the cursor selection on the timeline.
 71    public void ResetInput()
 5372    {
 5373        Editing = false;
 5374        ActiveField = 0;
 5375        InputBuffer.Clear();
 5376        InputCursor = 0;
 5377        TicketBuffer.Clear();
 5378        TicketCursor = 0;
 5379    }
 80}