32 lines
902 B
C++
32 lines
902 B
C++
#pragma once
|
|
#include <string>
|
|
#include <expected>
|
|
#include <functional>
|
|
#include <atomic>
|
|
|
|
extern std::atomic<bool> ctrlc_request;
|
|
|
|
// Trim whitespace from both ends of a string
|
|
std::string trim(const std::string& s);
|
|
|
|
// Generate a random alphanumeric string
|
|
std::string random_string(size_t length = 8);
|
|
|
|
// Generate a random temp file path
|
|
std::string random_file_name(size_t length = 8);
|
|
|
|
// RAII defer helper class for cleanup
|
|
class Defer {
|
|
std::function<void()> fn;
|
|
|
|
public:
|
|
Defer(std::function<void()> f) : fn(f) {}
|
|
~Defer() { fn(); }
|
|
};
|
|
|
|
// Spawn an editor with initial content and return the content after the separator (-- >8 --)
|
|
std::expected<std::string, std::string> spawn_editor(const std::string& initial_content);
|
|
|
|
// Parse an unsigned long from a C-string, returning an error if parsing fails
|
|
std::expected<unsigned long, std::string> string_toul(std::string const& str);
|