Skip to content

Commit

Permalink
update versioning scheme and hide version from top bar
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Jun 30, 2024
1 parent a7434a9 commit f3df2e7
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ file (platform-dependent defaults are left empty below):
signature=0
tab_size=8
terminal_title=
top_bar_show_version=0
unread_indicator=N

### attachment_indicator
Expand Down
37 changes: 37 additions & 0 deletions make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ TESTS="0"
DOC="0"
INSTALL="0"
SRC="0"
BUMP="0"
case "${1%/}" in
deps)
DEPS="1"
Expand Down Expand Up @@ -54,6 +55,10 @@ case "${1%/}" in
SRC="1"
;;

bump)
BUMP="1"
;;

all)
DEPS="1"
BUILD="1"
Expand All @@ -72,6 +77,7 @@ case "${1%/}" in
echo " install - perform build and install"
echo " all - perform deps, build, tests, doc and install"
echo " src - perform source code reformatting"
echo " bump - perform version bump"
exit 1
;;
esac
Expand Down Expand Up @@ -118,6 +124,37 @@ if [[ "${SRC}" == "1" ]]; then
exiterr "unrustify failed, exiting."
fi

# bump
if [[ "${BUMP}" == "1" ]]; then
CURRENT_VERSION=$(grep NMAIL_VERSION src/version.cpp | head -1 | awk -F'"' '{print $2}') # ex: 5.1.1
CURRENT_MAJMIN="$(echo ${CURRENT_VERSION} | cut -d'.' -f1,2)" # ex: 5.1
URL="https://github.com/d99kris/nmail.git"
LATEST_TAG=$(git -c 'versionsort.suffix=-' ls-remote --tags --sort='v:refname' ${URL} | tail -n1 | cut -d'/' -f3)
LATEST_VERSION=$(echo "${LATEST_TAG}" | cut -c2-) # ex: 5.1.3
LATEST_MAJMIN="$(echo ${LATEST_VERSION} | cut -d'.' -f1,2)" # ex: 5.1
SED="sed"
if [[ "$(uname)" == "Darwin" ]]; then
SED="gsed"
fi
if [[ "${CURRENT_MAJMIN}" == "${LATEST_MAJMIN}" ]]; then
NEW_MAJ="$(echo ${CURRENT_VERSION} | cut -d'.' -f1)" # ex: 5
let NEW_MIN=$(echo ${CURRENT_VERSION} | cut -d'.' -f2)+1
NEW_PATCH="1" # use 1-based build/snapshot number
NEW_VERSION="${NEW_MAJ}.${NEW_MIN}.${NEW_PATCH}"
echo "Current: ${CURRENT_MAJMIN} == ${LATEST_MAJMIN} Latest"
echo "Bump release: ${NEW_VERSION}"
${SED} -i "s/^#define NMAIL_VERSION .*/#define NMAIL_VERSION \"${NEW_VERSION}\"/g" src/version.cpp
else
NEW_MAJ="$(echo ${CURRENT_VERSION} | cut -d'.' -f1)" # ex: 5
NEW_MIN="$(echo ${CURRENT_VERSION} | cut -d'.' -f2)" # ex: 1
let NEW_PATCH=$(echo ${CURRENT_VERSION} | cut -d'.' -f3)+1
NEW_VERSION="${NEW_MAJ}.${NEW_MIN}.${NEW_PATCH}"
echo "Current: ${CURRENT_MAJMIN} != ${LATEST_MAJMIN} Latest"
echo "Bump build: ${NEW_VERSION}"
${SED} -i "s/^#define NMAIL_VERSION .*/#define NMAIL_VERSION \"${NEW_VERSION}\"/g" src/version.cpp
fi
fi

# build
if [[ "${BUILD}" == "1" ]]; then
OS="$(uname)"
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ int main(int argc, char* argv[])
THREAD_REGISTER();
Util::InitAppSignalHandlers();

const std::string appVersion = Version::GetUiAppVersion();
const std::string appVersion = Version::GetAppName(true /*p_WithVersion*/);
LOG_INFO("%s", appVersion.c_str());
std::string osArch = Util::GetOsArch();
LOG_INFO("%s", osArch.c_str());
Expand Down Expand Up @@ -511,7 +511,7 @@ static void ShowHelp()
static void ShowVersion()
{
std::cout <<
Version::GetUiAppVersion() << "\n"
Version::GetAppName(true /*p_WithVersion*/) << "\n"
"\n"
"Copyright (c) 2019-2024 Kristofer Berggren\n"
"\n"
Expand Down
2 changes: 1 addition & 1 deletion src/nmail.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH NMAIL "1" "June 2024" "nmail v4.72" "User Commands"
.TH NMAIL "1" "June 2024" "nmail 5.1.1" "User Commands"
.SH NAME
nmail \- ncurses mail
.SH SYNOPSIS
Expand Down
6 changes: 4 additions & 2 deletions src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ void Ui::Init()
{ "localized_subject_prefixes", "" },
{ "signature", "0" },
{ "terminal_title", "" },
{ "top_bar_show_version", "0" },
};
const std::string configPath(Util::GetApplicationDir() + std::string("ui.conf"));
m_Config = Config(configPath, defaultConfig);
Expand Down Expand Up @@ -356,6 +357,7 @@ void Ui::Init()
m_SearchShowFolder = m_Config.Get("search_show_folder") == "1";
Util::SetLocalizedSubjectPrefixes(m_Config.Get("localized_subject_prefixes"));
m_Signature = m_Config.Get("signature") == "1";
m_TopBarShowVersion = m_Config.Get("top_bar_show_version") == "1";

try
{
Expand Down Expand Up @@ -527,8 +529,8 @@ void Ui::DrawTop()
werase(m_TopWin);
wattron(m_TopWin, m_AttrsTopBar);

std::string version = " " + Version::GetUiAppVersion();
std::string topLeft = Util::TrimPadString(version, (m_ScreenWidth - 13) / 2);
static const std::string appName = " " + Version::GetAppName(m_TopBarShowVersion);
std::string topLeft = Util::TrimPadString(appName, (m_ScreenWidth - 13) / 2);
std::string status = GetStatusStr();
std::string topRight = status + " ";
int centerWidth = m_ScreenWidth - (int)topLeft.size() - (int)topRight.size() - 2;
Expand Down
1 change: 1 addition & 0 deletions src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ class Ui
bool m_ShowFullHeader = false;
bool m_SearchShowFolder = false;
bool m_Signature = false;
bool m_TopBarShowVersion = false;

std::string m_TerminalTitle;

Expand Down
13 changes: 3 additions & 10 deletions src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "version.h"

#define NMAIL_VERSION "4.72"
#define NMAIL_VERSION "5.1.1"

std::string Version::GetBuildOs()
{
Expand Down Expand Up @@ -39,14 +39,7 @@ std::string Version::GetCompiler()
#endif
}

std::string Version::GetMessageIdAppVersion()
std::string Version::GetAppName(bool p_WithVersion)
{
static std::string version = "nmail." NMAIL_VERSION;
return version;
}

std::string Version::GetUiAppVersion()
{
static std::string version = "nmail v" NMAIL_VERSION;
return version;
return std::string("nmail") + (p_WithVersion ? " " NMAIL_VERSION : "");
}
5 changes: 2 additions & 3 deletions src/version.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// version.h
//
// Copyright (c) 2022 Kristofer Berggren
// Copyright (c) 2022-2024 Kristofer Berggren
// All rights reserved.
//
// nmail is distributed under the MIT license, see LICENSE for details.
Expand All @@ -14,6 +14,5 @@ class Version
public:
static std::string GetBuildOs();
static std::string GetCompiler();
static std::string GetMessageIdAppVersion();
static std::string GetUiAppVersion();
static std::string GetAppName(bool p_WithVersion);
};

0 comments on commit f3df2e7

Please sign in to comment.