<commit_before>﻿//
// Copyright (c) Antmicro
//
// Full license details are defined in the 'LICENSE' file.
//
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xwt;
using Xwt.Drawing;

namespace Terminal
{
    public class Terminal : HBox
    {
        public Terminal()
        {
            rows = new List<IRow>();
            heightMap = new double[0];
            layoutParameters = new LayoutParameters(Font);
            Margins = new Rectangle();
            BackgroundColor = Colors.Black;
            PrepareLayoutParameters();
            canvas = new TerminalCanvas(this);
            PackStart(canvas, true, true);
            scrollbar = new VScrollbar();
            scrollbar.Sensitive = false;
            PackEnd(scrollbar);

            canvas.MouseScrolled += OnCanvasMouseScroll;
            canvas.BoundsChanged += OnCanvasBoundsChanged;
            scrollbar.StepIncrement = 15; // TODO

            scrollbar.ValueChanged += OnScrollbarValueChanged;
        }

        public void AppendRow(IRow row)
        {
            rowsGeneration++;
            var weWereAtEnd = scrollbar.Value == GetMaximumScrollbarValue();
            rows.Add(row);
            AddToHeightMap(row.PrepareForDrawing(layoutParameters));
            canvas.QueueDraw();

            scrollbar.Sensitive = GetMaximumHeight() > canvas.Bounds.Height;

            scrollbar.PageSize = canvas.Bounds.Height;
            scrollbar.UpperValue = GetMaximumHeight();
            if(weWereAtEnd)
            {
                scrollbar.Value = scrollbar.UpperValue - canvas.Bounds.Height;
            }
        }

        public new void Clear()
        {
            rowsGeneration++;
            rows.Clear();
            Refresh();
        }

        public int Count
        {
            get
            {
                return rows.Count;
            }
        }

        public Rectangle Margins { get; set; }

        private void OnScrollbarValueChanged(object sender, EventArgs e)
        {
            double rowOffset;
            canvas.FirstRowToDisplay = FindRowIndexAtPosition(scrollbar.Value, out rowOffset);
            canvas.Offset = scrollbar.Value - rowOffset;
            canvas.QueueDraw();
        }

        private void OnCanvasMouseScroll(object sender, MouseScrolledEventArgs e)
        {<commit_msg>Marked Margins as TODO.<commit_after>﻿//
// Copyright (c) Antmicro
//
// Full license details are defined in the 'LICENSE' file.
//
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xwt;
using Xwt.Drawing;

namespace Terminal
{
    public class Terminal : HBox
    {
        public Terminal()
        {
            rows = new List<IRow>();
            heightMap = new double[0];
            layoutParameters = new LayoutParameters(Font);
            Margins = new Rectangle();
            BackgroundColor = Colors.Black;
            PrepareLayoutParameters();
            canvas = new TerminalCanvas(this);
            PackStart(canvas, true, true);
            scrollbar = new VScrollbar();
            scrollbar.Sensitive = false;
            PackEnd(scrollbar);

            canvas.MouseScrolled += OnCanvasMouseScroll;
            canvas.BoundsChanged += OnCanvasBoundsChanged;
            scrollbar.StepIncrement = 15; // TODO

            scrollbar.ValueChanged += OnScrollbarValueChanged;
        }

        public void AppendRow(IRow row)
        {
            rowsGeneration++;
            var weWereAtEnd = scrollbar.Value == GetMaximumScrollbarValue();
            rows.Add(row);
            AddToHeightMap(row.PrepareForDrawing(layoutParameters));
            canvas.QueueDraw();

            scrollbar.Sensitive = GetMaximumHeight() > canvas.Bounds.Height;

            scrollbar.PageSize = canvas.Bounds.Height;
            scrollbar.UpperValue = GetMaximumHeight();
            if(weWereAtEnd)
            {
                scrollbar.Value = scrollbar.UpperValue - canvas.Bounds.Height;
            }
        }

        public new void Clear()
        {
            rowsGeneration++;
            rows.Clear();
            Refresh();
        }

        public int Count
        {
            get
            {
                return rows.Count;
            }
        }

        public Rectangle Margins { get; set; } // TODO

        private void OnScrollbarValueChanged(object sender, EventArgs e)
        {
            double rowOffset;
            canvas.FirstRowToDisplay = FindRowIndexAtPosition(scrollbar.Value, out rowOffset);
            canvas.Offset = scrollbar.Value - rowOffset;
            canvas.QueueDraw();
        }

        private void OnCanvasMouseScroll(object sender, MouseScrolledEventArgs e)
        {
{'fraction_non_alphanumeric': 0.0865187011919441, 'fraction_numerical': 0.0012330456226880395, 'mean_word_length': 1.8116695551704218, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '557851', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1191, 'n_words': 276}