codelite icon indicating copy to clipboard operation
codelite copied to clipboard

[Bug]: Unexpected "Return" key behaviour

Open EmilyGraceSeville7cf opened this issue 3 years ago • 1 comments

What happened?

Return key doesn't work as expected in a CodeLite terminal:

image

Between these two digits Return was pressed.

My program:

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <optional>

using std::string;
using std::vector;
using std::map;
using std::optional;

template <typename TKey, typename TValue, int MAX_CAPACITY>
class cache_t {
private:
    static_assert (MAX_CAPACITY > 0, "MAX_CAPACITY should be positive");
    map<TKey, TValue> source;
    
public:
    optional<TValue> try_get (TKey key) {
        auto iterator = source.find (key);
        if (iterator != source.end())
            return iterator->second;
        return {};
    }
    
    void try_add_or_replace (TKey key, TValue value) {
        if (source.size() < MAX_CAPACITY)
            source.insert_or_assign (key, value);
        else {
            auto iterator = source.find (key);
            if (iterator != source.end())
                iterator->second = value;
        }
    }
};

template <typename T> size_t binary_search (const vector<T> &source, int item) {
    int low = 0;
    int high = source.size() - 1;
    int item_index = source.size();
    
    while (low <= high) {
        int middle_index = (high + low) / 2;
        int middle = source[middle_index];
        if (item > middle)
            low = middle_index + 1;
        else if (item < middle)
            high = middle_index - 1;
        else {
            item_index = middle_index;
            high = middle_index - 1;
        }
    }
    
    return item_index;
}

int main() {
    std::ios_base::sync_with_stdio (false);
    int item_count;
    std::cin >> item_count;
    
    vector<int> items (item_count);
    for (auto i = 0; i < item_count; i++)
        std::cin >> items[i];
        
    int search_item_count;
    std::cin >> search_item_count;
    
    vector<int> search_items (search_item_count);
    for (auto i = 0; i < search_item_count; i++)
        std::cin >> search_items[i];
        
    cache_t<int, size_t, 3> cache;
    
    for (auto item : search_items) {
        size_t index;
        auto cached_item_index = cache.try_get (item);
        if (cached_item_index.has_value())
            index = cached_item_index.value();
        else
            index = binary_search (items, item);
        cache.try_add_or_replace (item, index);
        std::cout << (1 - (index == items.size())) << " ";
        
        size_t l = 0;
        if (index < items.size())
            l = index;
        while (l < items.size() && items[l] < item)
            l++;
            
        size_t r = l;
        while (r < items.size() && items[r] <= item)
            r++;
            
        std::cout << l << " " << r << std::endl;
    }
}

Version

16.0.0

Operating system

Linux

Steps to reproduce

- Launch program
- Type `1`
- Press `Return` key
- Type `1`
- Get two numbers on the same line

Relevant log output

No response

EmilyGraceSeville7cf avatar Oct 14 '22 16:10 EmilyGraceSeville7cf

Thanks for reporting this. As a workaround:

settings -> preferences -> terminal and select one of the native Linux terminals (e.g. gnome-terminal)

eranif avatar Oct 14 '22 17:10 eranif

As I plan on removing codelite-terminal (already removed from macOS) I am going to close this issue

eranif avatar Dec 11 '22 10:12 eranif

No problem (for me). As I use VS Code now. :) To clarify, do you wanna to use external terminal or rewrite codelite-terminal entirely?

EmilyGraceSeville7cf avatar Dec 13 '22 04:12 EmilyGraceSeville7cf