notnow 0.3.10

A terminal based task and TODO management software.
Documentation
// Copyright (C) 2018-2025 Daniel Mueller <deso@posteo.net>
// SPDX-License-Identifier: GPL-3.0-or-later

//! A module providing serialization and deserialization support for the
//! program's state objects.

use serde::Deserialize;
use serde::Serialize;

use crate::colors::Colors;
use crate::ser::tags::Tag;
use crate::ser::tasks::Tasks;
use crate::ser::tasks::TasksMeta;
use crate::ser::view::View;


/// A struct comprising the program's UI configuration.
#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct UiConfig {
  // We keep the colors at the start of the struct because that means
  // they will be at the start of the file and they are the most likely
  // to be modified by a user.
  #[serde(default)]
  pub colors: Colors,
  /// The tag to toggle on user initiated action.
  #[serde(default, skip_serializing_if = "Option::is_none")]
  pub toggle_tag: Option<Tag>,
  #[serde(default, skip_serializing_if = "Vec::is_empty")]
  pub views: Vec<View>,
}


/// A struct comprising the program's UI state.
#[derive(Debug, Default, Deserialize, PartialEq, Eq, Serialize)]
pub struct UiState {
  #[serde(default, skip_serializing_if = "Vec::is_empty")]
  pub selected_tasks: Vec<Option<usize>>,
  #[serde(default, skip_serializing_if = "Option::is_none")]
  pub selected_view: Option<usize>,
}


/// A struct comprising the task state of the program.
///
/// Note that this type is not actually serialized or deserialized in
/// this form directly. It merely acts as a way of grouping
/// functionality that is frequently used alongside each other.
///
#[derive(Debug, Default, PartialEq)]
pub struct TaskState {
  /// Meta data about tasks.
  pub tasks_meta: TasksMeta,
  /// A list of tasks.
  pub tasks: Tasks,
}