<commit_before>//===--- TextInput.cpp - Main Interface -------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  This file defines the main interface for the TextInput library.
//
//  <NAME> <<EMAIL>>, 2011-05-12
//===----------------------------------------------------------------------===//

#include "textinput/TextInput.h"
#include "textinput/Display.h"
#include "textinput/Reader.h"
#include "textinput/Color.h"
#include "textinput/Editor.h"
#include "textinput/History.h"
#include "textinput/KeyBinding.h"
#include "textinput/TextInputContext.h"
#include "textinput/SignalHandler.h"

#include <algorithm>
#include <functional>

namespace textinput {
  TextInput::TextInput(Reader& reader, Display& display,
                       const char* HistFile /* = 0 */):
  fHidden(false),
  fAutoHistAdd(true),
  fLastKey(0),
  fMaxChars(0),
  fLastReadResult(kRRNone),
  fActive(false),
  fNeedPromptRedraw(false)
  {
    fContext = new TextInputContext(this, HistFile);
    fContext->AddDisplay(display);
    fContext->AddReader(reader);
  }

  TextInput::~TextInput() {
    delete fContext;
  }

  void
  TextInput::TakeInput(std::string &input) {
    if (fLastReadResult != kRRReadEOLDelimiter
        && fLastReadResult != kRREOF) {
      input.clear();
      return;
    }
    input = fContext->GetLine().GetText();
    while (!input.empty() && input[input.length() - 1] == 13) {
      input.erase(input.length() - 1);
    }
    fContext->GetEditor()->ResetText();

    // Signal displays that the input got taken.
    std::for_each(fContext->GetDisplays().begin(), fContext->GetDisplays().end(),
             std::mem_fun(&Display::NotifyResetInput));

    ReleaseInputOutput();

    if (fLastReadResult == kRRReadEOLDelimiter) {
      // Input has been taken, we can continue reading.
      fLastReadResult = kRRNone;
    } // else keep EOF.
  }

  bool
  TextInput::HavePendingInput() const {
    if (!fActive) {
      GrabInputOutput();
    }
    for (std::vector<Reader*>::const_iterator iR = fContext->GetReaders().begin(),
         iE = fContext->GetReaders().end(); iR != iE; ++iR) {
      if ((*iR)->HavePendingInput(false))
        return true;
    }
    return false;
  }

  TextInput::EReadResult
  TextInput::ReadInput() {
    // Read more input.

    // Don't read if we are at the end; force call to TakeInput().
    if (fLastReadResult == kRRReadEOLDelimiter
        || fLastReadResult == kRREOF)
      return fLastReadResult;<commit_msg>Trigger redraw of prompt after ResetInput() even if prompt remains the same.<commit_after>//===--- TextInput.cpp - Main Interface -------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  This file defines the main interface for the TextInput library.
//
//  <NAME> <<EMAIL>>, 2011-05-12
//===----------------------------------------------------------------------===//

#include "textinput/TextInput.h"
#include "textinput/Display.h"
#include "textinput/Reader.h"
#include "textinput/Color.h"
#include "textinput/Editor.h"
#include "textinput/History.h"
#include "textinput/KeyBinding.h"
#include "textinput/TextInputContext.h"
#include "textinput/SignalHandler.h"

#include <algorithm>
#include <functional>

namespace textinput {
  TextInput::TextInput(Reader& reader, Display& display,
                       const char* HistFile /* = 0 */):
  fHidden(false),
  fAutoHistAdd(true),
  fLastKey(0),
  fMaxChars(0),
  fLastReadResult(kRRNone),
  fActive(false),
  fNeedPromptRedraw(false)
  {
    fContext = new TextInputContext(this, HistFile);
    fContext->AddDisplay(display);
    fContext->AddReader(reader);
  }

  TextInput::~TextInput() {
    delete fContext;
  }

  void
  TextInput::TakeInput(std::string &input) {
    if (fLastReadResult != kRRReadEOLDelimiter
        && fLastReadResult != kRREOF) {
      input.clear();
      return;
    }
    input = fContext->GetLine().GetText();
    while (!input.empty() && input[input.length() - 1] == 13) {
      input.erase(input.length() - 1);
    }
    fContext->GetEditor()->ResetText();

    // Signal displays that the input got taken.
    std::for_each(fContext->GetDisplays().begin(), fContext->GetDisplays().end(),
             std::mem_fun(&Display::NotifyResetInput));

    ReleaseInputOutput();

    if (fLastReadResult == kRRReadEOLDelimiter) {
      // Input has been taken, we can continue reading.
      fLastReadResult = kRRNone;
      // We will have to redraw the prompt, even if unchanged.
      fNeedPromptRedraw = true;
    } // else keep EOF.
  }

  bool
  TextInput::HavePendingInput() const {
    if (!fActive) {
      GrabInputOutput();
    }
    for (std::vector<Reader*>::const_iterator iR = fContext->GetReaders().begin(),
         iE = fContext->GetReaders().end(); iR != iE; ++iR) {
      if ((*iR)->HavePendingInput(false))
        return true;
    }
    return false;
  }

  TextInput::EReadResult
  TextInput::ReadInput() {
    // Read more input.

    // Don't read if we are at the end; force call to TakeInput().
    if (fLastReadResult == kRRReadEOLDelimiter
        || fLastReadResult == kRREOF)
      return fLastReadResult;
{'fraction_non_alphanumeric': 0.20139885222381634, 'fraction_numerical': 0.005380200860832138, 'mean_word_length': 2.4511138613861387, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3821075', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1674, 'n_words': 378}