Skip to content

Commit

Permalink
Accessor for CSI params.
Browse files Browse the repository at this point in the history
  • Loading branch information
mridgers committed May 30, 2018
1 parent b79406f commit 4111e10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion clink/terminal/include/terminal/ecma48_iter.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ class ecma48_code
char intermediate;
bool private_use;
unsigned char param_count;
int params[1];
int get_param(int index, int fallback=0) const;
};

template <int PARAM_N>
struct csi : public csi_base
{
int params[PARAM_N];
static const int max_param_count = PARAM_N;

private:
int buffer[PARAM_N - 1];
};

const char* get_pointer() const { return m_str; }
Expand All @@ -74,6 +79,15 @@ class ecma48_code
unsigned char m_code;
};

//------------------------------------------------------------------------------
inline int ecma48_code::csi_base::get_param(int index, int fallback) const
{
if (unsigned(index) < unsigned(param_count))
return *(params + index);

return fallback;
}

//------------------------------------------------------------------------------
template <int S>
bool ecma48_code::decode_csi(csi<S>& csi) const
Expand Down
4 changes: 2 additions & 2 deletions clink/terminal/test/ecma48.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ TEST_CASE("ecma48 c1 csi params")
REQUIRE(code->get_length() == 25);

REQUIRE(code->decode_csi(csi));
REQUIRE(csi.param_count == sizeof_array(csi.params));
REQUIRE(csi.param_count == decltype(csi)::max_param_count);

new (&iter) ecma48_iter("\x1b[1;2;3;4;5;6;7;8;1;2;3;4;5;6;7;8m", g_state);
REQUIRE(code->decode_csi(csi));
REQUIRE(csi.param_count == sizeof_array(csi.params));
REQUIRE(csi.param_count == decltype(csi)::max_param_count);
}

//------------------------------------------------------------------------------
Expand Down

0 comments on commit 4111e10

Please sign in to comment.