Skip to content

Commit afa6b79

Browse files
committed
[prompt] restore alt value
1 parent 7a6751f commit afa6b79

15 files changed

+316
-224
lines changed

src/base/attr_line.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ attr_line_t::from_table_cell_content(const string_fragment& content,
5151
static constexpr auto LF_SYMBOL = "\u240a"sv;
5252
static constexpr auto CR_SYMBOL = "\u240d"sv;
5353
static constexpr auto REP_SYMBOL = "\ufffd"sv;
54-
static const std::string ELLIPSIS = "\u22ef";
54+
static constexpr auto ELLIPSIS = "\u22ef"_frag;
5555

5656
auto has_ansi = false;
5757
size_t char_width = 0;
@@ -191,6 +191,7 @@ attr_line_t&
191191
attr_line_t::with_ansi_string(const std::string& str)
192192
{
193193
this->al_string = str;
194+
this->al_attrs.clear();
194195
scrub_ansi_string(this->al_string, &this->al_attrs);
195196

196197
return *this;
@@ -200,6 +201,7 @@ attr_line_t&
200201
attr_line_t::with_ansi_string(const string_fragment& str)
201202
{
202203
this->al_string = str.to_string();
204+
this->al_attrs.clear();
203205
scrub_ansi_string(this->al_string, &this->al_attrs);
204206

205207
return *this;

src/base/attr_line.hh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,19 @@ public:
320320
return *this;
321321
}
322322

323+
attr_line_t& append(const std::pair<string_fragment, role_t> value)
324+
{
325+
size_t start_len = this->al_string.length();
326+
327+
this->al_string.append(value.first.data(), value.first.length());
328+
329+
line_range lr{(int) start_len, (int) this->al_string.length()};
330+
331+
this->al_attrs.emplace_back(lr, VC_ROLE.value(value.second));
332+
333+
return *this;
334+
}
335+
323336
template<typename S>
324337
attr_line_t& append_quoted(const std::pair<S, string_attr_pair>& value)
325338
{
@@ -469,6 +482,24 @@ public:
469482
return *this;
470483
}
471484

485+
attr_line_t& insert(size_t index, const std::string& str)
486+
{
487+
this->al_string.insert(index, str.data(), str.length());
488+
489+
shift_string_attrs(this->al_attrs, index, str.length());
490+
491+
return *this;
492+
}
493+
494+
attr_line_t& insert(size_t index, string_fragment str)
495+
{
496+
this->al_string.insert(index, str.data(), str.length());
497+
498+
shift_string_attrs(this->al_attrs, index, str.length());
499+
500+
return *this;
501+
}
502+
472503
template<typename S>
473504
attr_line_t& insert(size_t index,
474505
const std::pair<S, string_attr_pair>& value)
@@ -487,6 +518,23 @@ public:
487518
return *this;
488519
}
489520

521+
attr_line_t& insert(size_t index,
522+
const std::pair<string_fragment, role_t>& value)
523+
{
524+
size_t start_len = this->al_string.length();
525+
526+
this->insert(index, value.first);
527+
528+
line_range lr{
529+
(int) index,
530+
(int) (index + (this->al_string.length() - start_len)),
531+
};
532+
533+
this->al_attrs.emplace_back(lr, VC_ROLE.value(value.second));
534+
535+
return *this;
536+
}
537+
490538
template<typename... Args>
491539
attr_line_t& add_header(Args... args)
492540
{

src/base/intern_string.hh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ struct string_fragment {
149149
{
150150
}
151151

152-
bool is_valid() const
152+
constexpr bool is_valid() const
153153
{
154154
return this->sf_begin != -1 && this->sf_begin <= this->sf_end;
155155
}
156156

157-
int length() const { return this->sf_end - this->sf_begin; }
157+
constexpr int length() const { return this->sf_end - this->sf_begin; }
158158

159159
Result<ssize_t, const char*> utf8_length() const;
160160

@@ -164,7 +164,7 @@ struct string_fragment {
164164

165165
size_t column_width() const;
166166

167-
const char* data() const { return &this->sf_string[this->sf_begin]; }
167+
constexpr const char* data() const { return &this->sf_string[this->sf_begin]; }
168168

169169
const unsigned char* udata() const
170170
{
@@ -176,13 +176,13 @@ struct string_fragment {
176176
return (char*) &this->sf_string[this->sf_begin + offset];
177177
}
178178

179-
char front() const { return this->sf_string[this->sf_begin]; }
179+
constexpr char front() const { return this->sf_string[this->sf_begin]; }
180180

181181
uint32_t front_codepoint() const;
182182

183-
char back() const { return this->sf_string[this->sf_end - 1]; }
183+
constexpr char back() const { return this->sf_string[this->sf_end - 1]; }
184184

185-
void pop_back()
185+
constexpr void pop_back()
186186
{
187187
if (!this->empty()) {
188188
this->sf_end -= 1;
@@ -200,7 +200,7 @@ struct string_fragment {
200200

201201
string_fragment sub_cell_range(int cell_start, int cell_end) const;
202202

203-
const char& operator[](size_t index) const
203+
constexpr const char& operator[](size_t index) const
204204
{
205205
return this->sf_string[sf_begin + index];
206206
}
@@ -291,7 +291,7 @@ struct string_fragment {
291291
return *suffix == '\0';
292292
}
293293

294-
string_fragment substr(int begin) const
294+
constexpr string_fragment substr(int begin) const
295295
{
296296
return string_fragment{
297297
this->sf_string, this->sf_begin + begin, this->sf_end};
@@ -309,13 +309,13 @@ struct string_fragment {
309309
this->sf_string, this->sf_begin + begin, this->sf_begin + end};
310310
}
311311

312-
bool contains(const string_fragment& sf) const
312+
constexpr bool contains(const string_fragment& sf) const
313313
{
314314
return this->sf_string == sf.sf_string && this->sf_begin <= sf.sf_begin
315315
&& sf.sf_end <= this->sf_end;
316316
}
317317

318-
size_t count(char ch) const
318+
constexpr size_t count(char ch) const
319319
{
320320
size_t retval = 0;
321321

0 commit comments

Comments
 (0)