Skip to content

Commit

Permalink
Fixing c++ errors (#16)
Browse files Browse the repository at this point in the history
* Fixing c++ errors

* Refinement for the Merge request
  • Loading branch information
maddimax authored and arximboldi committed Jan 31, 2019
1 parent 00f1a86 commit 458b1fc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/ewig/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,10 @@ text selected_text(buffer buf)
: buf.content)
.take(ends.row + 1)
.drop(starts.row)
.update(ends.row-starts.row, [&] (auto l) {
.update(ends.row-starts.row, [&, ends = ends] (auto l) {
return l.take(line_char(l, ends.col));
})
.update(0, [&] (auto l) {
.update(0, [&, starts = starts] (auto l) {
return l.drop(line_char(l, starts.col));
});
}
Expand All @@ -500,14 +500,14 @@ std::pair<buffer, text> cut(buffer buf)
: buf.content;
buf.content = content
.take(starts.row + 1)
.update(starts.row, [&] (auto l1) {
.update(starts.row, [&, ends = ends, starts = starts] (auto l1) {
auto l2 = content[ends.row];
return l1.take(line_char(l1, starts.col))
+ l2.drop(line_char(l2, ends.col));
})
+ buf.content.drop(ends.row + 1);
} else {
buf.content = buf.content.update(starts.row, [&] (auto l) {
buf.content = buf.content.update(starts.row, [&, starts = starts, ends = ends] (auto l) {
return l.take(line_char(l, starts.col))
+ l.drop(line_char(l, ends.col));
});
Expand Down
19 changes: 12 additions & 7 deletions src/ewig/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
#include <scelta.hpp>

extern "C" {

#ifndef _XOPEN_SOURCE_EXTENDED
#define _XOPEN_SOURCE_EXTENDED
#endif

#include <ncurses.h>
}

Expand Down Expand Up @@ -85,7 +90,7 @@ void draw_text(const buffer& buf, coord size)
(index)buf.content.size());
auto [starts, ends] = display_selected_region(buf);

immer::for_each(first_ln, last_ln, [&] (auto ln) {
immer::for_each(first_ln, last_ln, [&, starts=starts, ends=ends] (auto ln) {
str.clear();
display_line_fill(ln, buf.scroll.col + col, 2*size.col, str);
::move(row, col);
Expand All @@ -94,9 +99,9 @@ void draw_text(const buffer& buf, coord size)
auto hl_first = row == starts.row ? std::max(starts.col, 0) : 0;
auto hl_last = row == ends.row ? std::max(ends.col, 0) : str.size();
::addnwstr(str.c_str(), hl_first);
::attron(COLOR_PAIR(color::selection));
::attron(COLOR_PAIR((int)color::selection));
::addnwstr(str.c_str() + hl_first, hl_last - hl_first);
::attroff(COLOR_PAIR(color::selection));
::attroff(COLOR_PAIR((int)color::selection));
::addnwstr(str.c_str() + hl_last, str.size() - hl_last);
} else {
::addwstr(str.c_str());
Expand Down Expand Up @@ -126,7 +131,7 @@ void draw_mode_line(const buffer& buf, index maxcol)
auto percentage = int(progress * 100);
::move(getcury(stdscr), maxcol - str.size() - 6);
attrset(A_NORMAL | A_BOLD);
::attron(COLOR_PAIR(color::mode_line_message));
::attron(COLOR_PAIR((int)color::mode_line_message));
::printw(" %s %*d%% ", str.c_str(), 2, percentage);
},
[&] (const loading_file& file) {
Expand All @@ -135,7 +140,7 @@ void draw_mode_line(const buffer& buf, index maxcol)
auto percentage = int(progress * 100);
::move(getcury(stdscr), maxcol - str.size() - 6);
attrset(A_NORMAL | A_BOLD);
::attron(COLOR_PAIR(color::mode_line_message));
::attron(COLOR_PAIR((int)color::mode_line_message));
::printw(" %s %*d%% ", str.c_str(), 2, percentage);
},
[](auto&&) {})(buf.from);
Expand All @@ -144,10 +149,10 @@ void draw_mode_line(const buffer& buf, index maxcol)
void draw_message(const message& msg)
{
attrset(A_NORMAL);
::attron(COLOR_PAIR(color::message));
::attron(COLOR_PAIR((int)color::message));
::addstr(" ");
::addstr(msg.content.get().c_str());
::attroff(COLOR_PAIR(color::message));
::attroff(COLOR_PAIR((int)color::message));
}

void draw_text_cursor(const buffer& buf, coord window_size)
Expand Down
8 changes: 7 additions & 1 deletion src/ewig/keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
#include <cassert>

extern "C" {

#ifndef _XOPEN_SOURCE_EXTENDED
#define _XOPEN_SOURCE_EXTENDED
#endif

#include <ncurses.h>
}


using namespace std::string_literals;

namespace ewig {
Expand Down Expand Up @@ -69,7 +75,7 @@ namespace {

key_seq from_special_str(const char* name)
{
auto id = ::tigetstr(name);
auto id = ::tigetstr((NCURSES_CONST char*)name);
if (!id || id == (char*)-1)
throw std::runtime_error{"tigetstr() error for: "s + name};
auto code = ::key_defined(name);
Expand Down
2 changes: 1 addition & 1 deletion src/ewig/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void run(int argc, const char** argv, const std::string& fname)
application{term.size(), key_map_emacs},
update,
draw,
lager::boost_asio_event_loop{serv, [&] { term.stop(); }},
lager::with_boost_asio_event_loop{serv, [&] { term.stop(); }},
enhancer);
term.start([&] (auto ev) { st.dispatch (ev); });
st.dispatch(command_action{"load", fname});
Expand Down
6 changes: 6 additions & 0 deletions src/ewig/terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@
#include <iostream>

extern "C" {

#ifndef _XOPEN_SOURCE_EXTENDED
#define _XOPEN_SOURCE_EXTENDED
#endif

#include <ncurses.h>
}


using namespace std::placeholders;
using namespace std::string_literals;

Expand Down

0 comments on commit 458b1fc

Please sign in to comment.