Skip to content

Commit

Permalink
Introduce til::rle - a run length encoded vector
Browse files Browse the repository at this point in the history
* #8000 - Supports buffer rewrite work. A re-use of `til::rle` will be
  useful as a column counter as we pursue NxM storage and presentation.
* #3075 - The new iterators allow skipping forward by multiple units,
  which wasn't possible under `TextBuffer-/OutputCellIterator`.
  Additionally it also allows a bulk insertions.
* #8787 and #410 - High probability this should be `pmr`-ified
  like `bitmap` for things like `chafa` and `cacafire`
  which are changing the run length frequently.

* [x] Closes #8741
* [x] I work here.
* [x] Tests added.
* [x] Tests passed.

- [x] Ran `cacafire` in `OpenConsole.exe` and it looked beautiful
- [x] Ran new suite of `RunLengthEncodingTests.cpp`

Co-authored-by: Michael Niksa <miniksa@microsoft.com>
  • Loading branch information
lhecker and miniksa committed May 14, 2021
1 parent bbe8275 commit ba58564
Show file tree
Hide file tree
Showing 25 changed files with 1,766 additions and 1,687 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/allow/allow.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Apc
apc
clickable
copyable
dalet
Dcs
dcs
Expand Down
6 changes: 4 additions & 2 deletions dep/telemetry/ProjectTelemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ Module Name:
- This module is used for basic definitions for telemetry for the entire project
--*/

#define TraceLoggingOptionMicrosoftTelemetry() TraceLoggingOptionGroup(0x9aa7a361, 0x583f, 0x4c09, 0xb1, 0xf1, 0xce, 0xa1, 0xef, 0x58, 0x63, 0xb0)
//#define TraceLoggingOptionMicrosoftTelemetry() TraceLoggingOptionGroup(0x9aa7a361, 0x583f, 0x4c09, 0xb1, 0xf1, 0xce, 0xa1, 0xef, 0x58, 0x63, 0xb0)
#define TraceLoggingOptionMicrosoftTelemetry() TraceLoggingOptionGroup(0x4f50731a, 0x89cf, 0x4782, 0xb3, 0xe0, 0xdc, 0xe8, 0xc9, 0x4, 0x76, 0xba)

#define TelemetryPrivacyDataTag(tag) TraceLoggingUInt64((tag), "PartA_PrivTags")
#define PDT_ProductAndServicePerformance 0x0u
#define PDT_ProductAndServiceUsage 0x0u
#define MICROSOFT_KEYWORD_TELEMETRY 0x0
#define MICROSOFT_KEYWORD_MEASURES 0x0
#define MICROSOFT_KEYWORD_MEASURES 0x0
565 changes: 30 additions & 535 deletions src/buffer/out/AttrRow.cpp

Large diffs are not rendered by default.

43 changes: 13 additions & 30 deletions src/buffer/out/AttrRow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ Revision History:

#pragma once

#include "TextAttributeRun.hpp"
#include "AttrRowIterator.hpp"
#include "til/rle.h"
#include "TextAttribute.hpp"

class ATTR_ROW final
{
using rle_vector = til::small_rle<TextAttribute, uint16_t, 1>;

public:
using const_iterator = typename AttrRowIterator;
using const_iterator = rle_vector::const_iterator;

ATTR_ROW(const UINT cchRowWidth, const TextAttribute attr)
noexcept;
ATTR_ROW(uint16_t width, TextAttribute attr);

~ATTR_ROW() = default;

Expand All @@ -39,28 +40,13 @@ class ATTR_ROW final
noexcept = default;
ATTR_ROW& operator=(ATTR_ROW&&) noexcept = default;

TextAttribute GetAttrByColumn(const size_t column) const;
TextAttribute GetAttrByColumn(const size_t column,
size_t* const pApplies) const;

size_t GetNumberOfRuns() const noexcept;

size_t FindAttrIndex(const size_t index,
size_t* const pApplies) const;

std::vector<uint16_t> GetHyperlinks();

bool SetAttrToEnd(const UINT iStart, const TextAttribute attr);
void ReplaceAttrs(const TextAttribute& toBeReplacedAttr, const TextAttribute& replaceWith) noexcept;

void Resize(const size_t newWidth);

[[nodiscard]] HRESULT InsertAttrRuns(const gsl::span<const TextAttributeRun> newAttrs,
const size_t iStart,
const size_t iEnd,
const size_t cBufferWidth);
TextAttribute GetAttrByColumn(uint16_t column) const;
std::vector<uint16_t> GetHyperlinks() const;

static std::vector<TextAttributeRun> PackAttrs(const std::vector<TextAttribute>& attrs);
bool SetAttrToEnd(uint16_t beginIndex, TextAttribute attr);
void ReplaceAttrs(const TextAttribute& toBeReplacedAttr, const TextAttribute& replaceWith);
void Resize(uint16_t newWidth);
void Replace(uint16_t beginIndex, uint16_t endIndex, const TextAttribute& newAttr);

const_iterator begin() const noexcept;
const_iterator end() const noexcept;
Expand All @@ -69,17 +55,14 @@ class ATTR_ROW final
const_iterator cend() const noexcept;

friend bool operator==(const ATTR_ROW& a, const ATTR_ROW& b) noexcept;
friend class AttrRowIterator;
friend class ROW;

private:
void Reset(const TextAttribute attr);

boost::container::small_vector<TextAttributeRun, 1> _list;
size_t _cchRowWidth;
rle_vector _data;

#ifdef UNIT_TESTING
friend class AttrRowTests;
friend class CommonState;
#endif
};
136 changes: 0 additions & 136 deletions src/buffer/out/AttrRowIterator.cpp

This file was deleted.

80 changes: 0 additions & 80 deletions src/buffer/out/AttrRowIterator.hpp

This file was deleted.

Loading

1 comment on commit ba58564

@github-actions
Copy link

@github-actions github-actions bot commented on ba58564 May 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

Unrecognized words, please review:

  • accidentially
Previously acknowledged words that are now absent AAAAABBBBBBBCCC AAAAABCCCCCCCCC AAAAADCCCCCCCCC cang memcopy rgch
To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the git@github.com:microsoft/terminal.git repository
on the dev/lhecker/rle branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spelling/expect/alphabet.txt
.github/actions/spelling/expect/expect.txt
.github/actions/spelling/expect/web.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect/ba585646368f700f7f711ff9b621f455e427cd09.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
}

comment_json=$(mktemp)
curl -L -s -S \
  --header "Content-Type: application/json" \
  "https://api.github.com/repos/microsoft/terminal/comments/50839292" > "$comment_json"
comment_body=$(mktemp)
jq -r .body < "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")
  

patch_add=$(perl -e '$/=undef;
$_=<>;
s{<details>.*}{}s;
s{^#.*}{};
s{\n##.*}{};
s{(?:^|\n)\s*\*}{}g;
s{\s+}{ }g;
print' < "$comment_body")
  
update_files
rm $comment_body
git add -u
✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

⚠️ The command is written for posix shells. You can copy the contents of each perl command excluding the outer ' marks and dropping any '"/"' quotation mark pairs into a file and then run perl file.pl from the root of the repository to run the code. Alternatively, you can manually insert the items...

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

🗜️ If you see a bunch of garbage

If it relates to a ...

well-formed pattern

See if there's a pattern that would match it.

If not, try writing one and adding it to a patterns/{file}.txt.

Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

Note that patterns can't match multiline strings.

binary-ish string

Please add a file path to the excludes.txt file instead of just accepting the garbage.

File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

Please sign in to comment.